Parse jsonstring output as json object in custom action

Hi Team,

We are implementing a function from third party api which returns jsonstring output. We are not able to parse that in custom action contracts.

Need help.

When we are executing the api we are getting result successfully but we are not able to parse it to get data and we are stuck here. Really need your advice on this.

We have in past successfully parsed API which return JSON Object.

Anway this is our contract:

And this is our Response setup:

We have tried other methods also and if we use response to parse Output it runs smoothly.

How to parse a jsonstring in json object here ?

or how to parse jsonformatted string to get data like I want to get data for name, email mobile.

Regards
Alok

Hi Team,

I have just caught the output as string and I am showing you how the data is coming from the API.

This is the output we get as JSONString and we need to convert it into JSON Object to parse data.

I change output contracts to map to the fields to show you these data.

Regards
Alok

Hi Alok,

Could you export your action and post it along with copying and pasting the output from the third party API. It is time consuming and error prone to retype everything from the images. Feel free to change the content of any of the sensitive strings to something generic like "blah" or "foo", just make sure not to change any of the formatting.

--Jason

Input Contract

{

"$schema": "http://json-schema.org/draft-04/schema#",

"title": "GetContactInfo",

"description": "Contact Information.",

"type": "object",

"required": [

"Mobile"

],

"properties": {

"Mobile": {

"type": "string",

"description": "Need Mobile to validate."

}

}

}

Output Contract:

{

"$schema": "http://json-schema.org/draft-04/schema#",

"title": "Contact",

"type": "object",

"properties": {

"Name": {

"type": "string"

},

"Email": {

"type": "string"

},

"Mobile": {

"type": "string"

}

}

}

Request Configuration

{

"requestUrlTemplate": "{credentials.url}?auth_type={credentials.auth_type}&zapikey=${credentials.zapikey}",

"requestType": "POST",

"headers": {

"Accept": "application/json"

},

"requestTemplate": "${input.rawRequest}"

}

Response:

{

"translationMap": {

"Contact": "$.details.output"

},

"translationMapDefaults": {},

"successTemplate": "${Contact}"

}

TEST

8. Execute

{

"code": "success",

"details": {

"output": "{"Name":"Alok Tibrewal","Email":"alok@siplnet.com","Mobile":"9830320582"}",

"output_type": "string",

"id": "136290000000020001"

},

"message": "function executed successfully"

}

9. Resolve translation map

{

"rawResult": "{\n "code" : "success",\n "details" : {\n "output" : "{\"Name\":\"Alok Tibrewal\",\"Email\":\"alok@siplnet.com\",\"Mobile\":\"9830320582\"}",\n "output_type" : "string",\n "id" : "136290000000020001"\n },\n "message" : "function executed successfully"\n}",

"Contact": ""{\"Name\":\"Alok Tibrewal\",\"Email\":\"alok@siplnet.com\",\"Mobile\":\"9830320582\"}""

}

10. Apply output transformation

"{"Name":"Alok Tibrewal","Email":"alok@siplnet.com","Mobile":"9830320582"}"

Do you need anything more. Any help how to parse json string will be helpful.

Regards
Alok

One more thing I want to add, we have facility to change return object structure. In the CRM we can create any json structure output.

Issue is that when they sent result back they convert it info JSONString.

For example I have also tried by changing the format at their end like this:

{
"code": "success",
"details": {
"output": "{"Contact":{"Name":"Alok Tibrewal","Email":"x@x.com","Mobile":"000000"}}",
"output_type": "string",
"id": "136290000000020001"
},
"message": "function executed successfully"
}

If you look at above I have wrapped the response under "Contact".

Issue I am facing or may be I don't know how to parse string json.

If you remember we have been working on a CRM where we are putting our embeded widget this is part of that project.

Regards
Alok

Unfortunately, this isn't something PureCloud can handle for you. The response must be JSON. As far as PureCloud is concerned, that output property is just a simple string. To use this service, you have two main options:

  1. Alter the service to send an actual JSON object instead of a string so that it can be consumed by PureCloud.
  2. Build a middleware service to pass the request through and alter the response to turn the string into actual JSON before it is returned to PureCloud.
1 Like

One other (ugly) possibility that comes to mind is that you might be able to use the architect "split" capability to break apart the JSON string and find what you are looking for from the response.

Both of the options that Tim provided would be much more robust, but you might be able to at least proof of concept out your work with some string hacking.

1 Like

Thanks guys for response.

Tim I am already following point 1 with the CRM company so that they can alter the response that way.

Middleware service we want to avoid and feel that should be last resort for us. Increase cost factor and maintenance.

Regards
Alok

Hi Tim

  1. Alter the service to send an actual JSON object instead of a string so that it can be consumed by PureCloud.

Able to do this in 3rd party CRM. All is well now.

Regards
Alok

1 Like

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