Integration/ Data Action/ JSON Mapping/ PopUp Scripts - Issue

Hello Everyone,

I would like to ask about JSON mapping to dynamic number of objects.
How this can be done? Any example/ resources?

As an example, we can use the following URL "https://jsonplaceholder.typicode.com/posts?userId=1" with the Postman with GET method, the response would be something similar to the following:

[ { "userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit" },
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint "
}]

So, as you can see, there are multiple objects,. However, the error message I always get from PureCloud is:
{
"status": 400,
"code": "invalid.extraction.into.translation.map",
"message": "There was an issue extracting a value from the remote endpoint's response into the response translation map. Cause: Expected to find an object with property ['id'] in path $ but found 'java.util.ArrayList'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.",
"messageParams": {},
"contextId": "65e04558-8c48-43ef-b281-5b15e70e6f93",
"details": [],
"errors": []
}

On other hand, when I work only with single object, in which the response does not start with "[", it works successfully.

Please, any idea, or suggestion can be helpful.

Thank you,

Hi Ali,

Take a look at this article, it may help with processing multiple records:

1 Like

As a note on the "invalid.extraction.into.translation.map" error that you are getting. I highly recommend grabbing the results you are getting from the execution and pasting those into a site like http://jsonpath.com/ and working through the JSONPath that you are using to populate the translation map.

This isn't a site we have any affiliation with, so I would definitely redact anything sensitive.

As an example, if you wanted to get an array of all of the titles you could use this for your JSONPath

$.*.title

--Jason

1 Like

Dear Smith,

Thank you very much for the feedback.
I have more questions related to popup scripts.
How I could display all the objects in the array on Pop-up Scripts? Is there a loop statement in the popup script that I can use?

I would like to GET these objects, and these will be displayed for Agents as a down-list/ checkbox / ets, for further process!!

Thank you and best regards,

Ali Aljohani

Dear Jason,

Thank you very much for the feedback.
Even though, I am stuck to access my second object from the following Json structure:

[ { "userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit" },
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint "
}]

your advise is really helpful, that JSOPath evaluation has to be the starting point regarding transition map.

Thank you very much,
Best Regards,
Ali Aljohani

This JSONPath expression will return the second entry in the array:
$.[1]

Here is a good tutorial on using JSONPath:
http://goessner.net/articles/JsonPath/index.html#e2

Hi Ali,

I'm not as familiar with scripts, but I don't believe adding UI components dynamically, such as in a loop, is possible. I have seen scripts were up to 'x' fields are pre-allocated, maybe 5, where some get used and some are left blank.

Thank you Jason,
I did not notice about indexing from 0.

Thank you again and all the best,
Ali Aljohani

Thank you Smith,
This is what I am aware of. I don't think script support loops. However, I will try your idea of setting a fixed number of fields to deal with the recent, for now.

Thank you again Smith,
All the best,
Ali Aljohani

1 Like

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