Genesys Cloud - Main

 View Only

Discussion Thread View
  • 1.  Data Action - Count Iteam is a Array Filtered from a Json Response

    Posted 11-26-2022 07:18
    Afternnon All,

    I am after some help.

    I would like to determine from  the following API if a Customer has spoken to more than one advisor:

    API: /api/v2/conversations/${input.conversationId}

    I would like to filter the results using the following in the translation map

    $.participants[?(@.purpose == 'agent')].purpose

    And count the items in the array, which would have one or many items.

    [
    "agent",
    "agent"
    ]

    I would like to return an integer on the output contract.

    Any advice would be apprecaited.
    #Unsure/Other

    ------------------------------
    Philip Penn
    ------------------------------


  • 2.  RE: Data Action - Count Iteam is a Array Filtered from a Json Response

    Posted 11-27-2022 19:32
    If your data action is returning an array, you should be able to use that collection as it comes into Architect and count the items using Count().

    ------------------------------
    Robert Wakefield-Carl
    Avtex Solutions, LLC
    Contact Center Innovation Architect
    https://www.Avtex.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 3.  RE: Data Action - Count Iteam is a Array Filtered from a Json Response

    Posted 11-29-2022 03:17
    Hi Robert

    Could you please give me some steer on how to acheive what you advised?

    Thansk Phil

    ------------------------------
    Philip Penn
    ------------------------------



  • 4.  RE: Data Action - Count Iteam is a Array Filtered from a Json Response

    Posted 11-28-2022 03:30

    Hi Philip,

    If you just need number of items, for translation  map try to use: 
    $.participants[?(@.purpose == 'agent')].purpose.size() 
    Contract value for output must be an integer type.

    regards



    ------------------------------
    Gerardo Rodríguez
    Evolutio Cloud Enabler, S.A.
    ------------------------------



  • 5.  RE: Data Action - Count Iteam is a Array Filtered from a Json Response

    Posted 11-28-2022 10:10

    Hi Gerardo.

    Thanks for your response.  

    I have attempted this

    Contact Json
    Input

    {
    "type": "object",
    "properties": {},
    "additionalProperties": true
    }
    Output
    {
    "type": "object",
    "properties": {
    "participantCount": {
    "type": "integer"
    }
    },
    "additionalProperties": true
    }

    TranslationMap
    {
    "translationMap": {
    "participantCount": "$.participants[?(@.purpose == 'agent')].purpose.size()"
    },
    "translationMapDefaults": {},
    "successTemplate": "{\n\"participantCount\": ${participantCount}\n}"
    }

    But I get this response

    {
      "message": "JSON failed schema validation for the following reasons: Schema: # @/properties/participantCount.  Error location: /participantCount.  instance type (array) does not match any allowed primitive type (allowed: [\"integer\"])",
      "code": "invalid.schema",
      "status": 400,
      "messageParams": {},
      "contextId": "6854452a-2dcb-48ee-98e1-908330282412",
      "details": [
        {
          "errorCode": "ACTION.PROCESSING"
        }
      ],
      "errors": []
    }


    Do you know what I am doing wrong?



    ------------------------------
    Philip Penn
    ------------------------------



  • 6.  RE: Data Action - Count Iteam is a Array Filtered from a Json Response

    Posted 11-28-2022 10:14
    {
    "name": "Surveys - Get RnR MetaData - Exported 2022-11-28 @ 15:12",
    "integrationType": "purecloud-data-actions",
    "actionType": "custom",
    "config": {
    "request": {
    "requestUrlTemplate": "/api/v2/conversations/[ConversationIDHere]",
    "requestType": "GET",
    "headers": {},
    "requestTemplate": "${input.rawRequest}"
    },
    "response": {
    "translationMap": {
    "participantCount": "$.participants[?(@.purpose == 'agent')].purpose.size()"
    },
    "translationMapDefaults": {},
    "successTemplate": "{\n\"participantCount\": ${participantCount}\n}"
    }
    },
    "contract": {
    "input": {
    "inputSchema": {
    "type": "object",
    "properties": {},
    "additionalProperties": true
    }
    },
    "output": {
    "successSchema": {
    "type": "object",
    "properties": {
    "participantCount": {
    "type": "integer"
    }
    },
    "additionalProperties": true
    }
    }
    },
    "secure": false
    }

    ------------------------------
    Philip Penn
    ------------------------------



  • 7.  RE: Data Action - Count Iteam is a Array Filtered from a Json Response

    Posted 11-29-2022 02:48
    Hi Philip,
    You can define the output parameter as array and then an item as integer:
    {
    "type": "object",
    "properties": {
    "undefined": {
    "type": "array",
    "items": {
    "title": "participantCount",
    "type": "integer"
    }
    }
    },
    "additionalProperties": true
    }

    But instead of doing that I think the solution proposed by Robert (count) is better and quickly for your case.

    ------------------------------
    Gerardo Rodríguez
    Evolutio Cloud Enabler, S.A.
    ------------------------------



  • 8.  RE: Data Action - Count Iteam is a Array Filtered from a Json Response

    Posted 11-30-2022 16:14
    Hi

    Following data action output will result an array of "agent"

    TranslationMap
    {
    "translationMap": {
    "participantCount": "$.participants[?(@.purpose == 'agent')].purpose"
    },
    "translationMapDefaults": {},
    "successTemplate": "{\n\"participantCount\": ${participantCount}\n}"
    }

    In the architect flow using "Call Data Action" block, map "participantCount" to a variable say "participantOut" under Success Output

    under the "Success" path using "Update Data" block, define an Integer type variable say "TotalCount" and under "Value to Assign" change to expression and set Count(Task.participantOut)

    TotalCount will now give you the number of agents involved. 

    Hope this helps.

    ------------------------------
    Muhammad Zubair Awan
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources