Getting no data for translatemap variable

I'm trying to understand why I'm getting "0" (my translationmapdefault) for the variable "TransferCount".
I'm filtering the participant data, and the data is there - I can see it in the rawResult.

{
"name": "Get Transferred Priority - Exported 2023-05-30 @ 22:22",
"integrationType": "purecloud-data-actions",
"actionType": "custom",
"config": {
"request": {
"requestUrlTemplate": "/api/v2/conversations/emails/${input.CONVERSATION_ID}",
"requestType": "GET",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"UserAgent": "PureCloudIntegrations/1.0"
},
"requestTemplate": "${input.rawRequest}"
},
"response": {
"translationMap": {
"TransferCount": "$.participants[?(@.disconnectType=="transfer" && @.purpose=="agent")]['id'].size()",
"OriginalPriority": "$.participants.[1]['conversationRoutingData']['priority']"
},
"translationMapDefaults": {
"OriginalPriority": "0"
},
"successTemplate": "{"TransferCount": ${TransferCount}, "OriginalPriority": ${OriginalPriority}}"
}
},
"contract": {
"input": {
"inputSchema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "ConversationIdRequest",
"description": "A Conversation ID-based request.",
"type": "object",
"required": [
"CONVERSATION_ID"
],
"properties": {
"CONVERSATION_ID": {
"description": "The conversation ID.",
"type": "string"
}
},
"additionalProperties": true
}
},
"output": {
"successSchema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Get conversation level data.",
"description": "Returns the variables requested from conversation data.",
"type": "object",
"properties": {
"TransferCount": {
"type": "integer"
},
"OriginalPriority": {
"type": "integer"
}
},
"additionalProperties": true
}
}
},
"secure": false
}

You should be able to try out your jsonpath against the results on a site like this one:

If some trial and error on that page doesn't help you figure out what the problem is please post the results you are running your jsonpath against. Feel free to xxxx out anything sensitive, but make sure that you keep the shape of the data unchanged.

--Jason

1 Like

Thanks Jason, I was using the jsonpath site and the filter works there. However, when I test it without the translationMapDefaults, I'm given:

9. Resolve translation map: Failed while processing the translation map. Could not resolve value for the key: 'TransferCount' and no default value was configured. Additional details: Expected character: )

The ")" is what throws me, I'm not missing a bracket?

I was able to figure out the missing & was the cause.
However, I'm trying to do a count of the returned items, but I'm getting it back in an array no matter what, with the values of "NULL":

{
"TransferCount": [
null,
null
],
"OriginalPriority": 0
}

{
"translationMap": {
"TransferCount": "$.participants[?(@.disconnectType=="transfer" && @.purpose=="agent")]['id'].size()",
"OriginalPriority": "$.participants.[1]['conversationRoutingData']['priority']"
},

Trying to reproduce your issue, I have learned something today :slight_smile:

From what I understand (what I found googling this), the issue is a limitation in JSONPath.
JSONPath doesn't/can't compute the size of an array resulting from a filter.
I mean $.records.size() would work - and return an integer.
But $.records[*].size() will return an array - JSONPath applying the size() function to each record object (each record matching the filter - * in this case).

But I wouldn't have included a smiley above if there were no workarounds.
Thanks to a method @Jason_Mathison had shared in the past.
The approach is to leverage Velocity Macros in the successTemplate to convert the result from translationMap and count the items.

This is my Response Configuration:

{
    "translationMap": {
        "TransferAgentsAsStr": "$.participants[?(@.disconnectType==\"transfer\" && @.purpose==\"agent\")].id",
        "OriginalPriority": "$.participants.[1]['conversationRoutingData']['priority']"
    },
    "translationMapDefaults": {
        "OriginalPriority": "0",
        "TransferAgentsAsStr": "[]"
    },
    "successTemplate": "#set ($TransferAgents = $TransferAgentsAsStr.replace(\"[\", \"\").replace(\"]\", \"\").replace(\" \", \"\").split(\",\")) {\"TransferCount\": ${TransferAgents.size()}, \"OriginalPriority\": ${OriginalPriority}}"
}

Although the results of the JSONPath expression is an array of string - TransferAgentsAsStr in my translationMap above - when it is passed/made available in the successTemplate, it is considered as a string.
The approach is then to convert this string to an array - using split and replace functions using Velocity Macros - TransferAgents variable in my successTemplate above. The count is then made with size method().

Regards,

Oh, wow. I would never have thought to do that! Thank you @Jerome.Saint-Marc! It works perfectly.

Take care,
Josh

I forgot to mention one thing.
In your Request configuration, for your "Content-Type" header, use "application/json" as value (instead of "application/x-www-form-urlencoded")
It is not causing a problem here, apparently. But correct value is "application/json".

Regards,

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.