ChadE | 2022-10-31 02:16:32 UTC | #1
Hi, I am attempting to extract a number of fields from a data action response which has the fields within an array. The JSON response of the data action is as follows:
{ "Name": "Peter Pan", "Phone": "0400000000", "Type": "Customer", "Applications": [ { "APPLICATIONID": 383931, "SERVICEORDERTYPE": "NEWCONNECTION" }, { "APPLICATIONID": 383505, "SERVICEORDERTYPE": "ALTERSUPPLY" }, { "APPLICATIONID": 383502, "SERVICEORDERTYPE": "ALTERSUPPLY" } ] }
I am wanting to extract each of the APPLICATIONID and SERVICEORDER_TYPE into separate fields for display in an agent script.
My Output Contract is
{ "title": "DataResponse", "type": "object", "properties": { "CallerName": { "type": "string" }, "CallerPhone": { "type": "string" }, "Applications": { "type": "array", "items": { "title": "Application", "type": "object", "properties": { "A1APPLICATIONID": { "type": "integer" }, "A2APPLICATIONID": { "type": "integer" }, "A3APPLICATIONID": { "type": "integer" }, "A1SERVICEORDERTYPE": { "type": "string" }, "A2SERVICEORDERTYPE": { "type": "string" }, "A3SERVICEORDER_TYPE": { "type": "string" } }, "additionalProperties": true } } }, "additionalProperties": true }
And my response config is the following:
{ "translationMap": { "CallerName": "$.Name", "CallerPhone": "$.Phone", "A1APPLICATIONID": "$['Applications'][0]['APPLICATIONID']", "A2APPLICATIONID": "$['Applications'][1]['APPLICATIONID']", "A3APPLICATIONID": "$['Applications'][2]['APPLICATIONID']", "A1SERVICEORDERTYPE": "$['Applications'][0]['SERVICEORDERTYPE']", "A2SERVICEORDERTYPE": "$['Applications'][1]['SERVICEORDERTYPE']", "A3SERVICEORDERTYPE": "$['Applications'][2]['SERVICEORDERTYPE']" }, "translationMapDefaults": { "CallerName": "\"UNKNOWN\"", "CallerPhone": "\"UNKNOWN\"", "A1APPLICATIONID": "\"0\"", "A2APPLICATIONID": "\"0\"", "A3APPLICATIONID": "\"0\"", "A1SERVICEORDERTYPE": "\"UNKNOWN\"", "A2SERVICEORDERTYPE": "\"UNKNOWN\"", "A3SERVICEORDERTYPE": "\"UNKNOWN\"" }, "successTemplate": "{\"CallerName\":${CallerName},\"CallerPhone\":${CallerPhone},\"A1APPLICATIONID\":${A1APPLICATIONID},\"A2APPLICATIONID\":${A2APPLICATIONID},\"A3APPLICATIONID\":${A3APPLICATIONID},\"A1SERVICEORDERTYPE\":${A1SERVICEORDERTYPE},\"A2SERVICEORDERTYPE\":${A2SERVICEORDERTYPE},\"A3SERVICEORDERTYPE\":${A3SERVICEORDER_TYPE}}" }
The data action runs with no errors however no data is returned in the ApplicationIDs or the ServiceOrder_Types - The Caller Name and Phone number is returned.
Can someone point me in the right direction?
Jerome.Saint-Marc | 2022-11-01 21:50:17 UTC | #2
Hello,
The problem comes from your Output Contract. I think you initially tried to map your response using Arrays in your output contract, and then changed your data action to extract the different values using your translationMap (but didn't modify your output contract accordingly - to remove Arrays declaration).
So based on your response and translationMap, it should now be set to:
{ "title": "DataResponse", "type": "object", "properties": { "CallerName": { "type": "string" }, "CallerPhone": { "type": "string" }, "A1APPLICATIONID": { "type": "integer" }, "A2APPLICATIONID": { "type": "integer" }, "A3APPLICATIONID": { "type": "integer" }, "A1SERVICEORDERTYPE": { "type": "string" }, "A2SERVICEORDERTYPE": { "type": "string" }, "A3SERVICEORDER_TYPE": { "type": "string" } }, "additionalProperties": true }
I also noticed a small error in your translationMap, in the translationMapDefaults attribute. The default value for A1APPLICATIONID, A2APPLICATIONID and A3APPLICATIONID is 0 (integer) - change "A1_APPLICATION_ID": "\"0\"" to "A1_APPLICATION_ID": "0"
Regards,
ChadE | 2022-11-01 21:50:13 UTC | #3
Thank you so much Jerome, That was exactly what I needed. I had struggled (very new to Genesys) and had tried a number of different ways.
system | 2022-12-02 21:50:51 UTC | #4
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 16976