Hello, I am attempting to convert this into Appian values, but I am having trouble.
What would be the best way to convert this?
Here is the raw response from an API:
{"response":"{\"requestId\":\"123456\",\"status\":0,\"description\":\"Success.\",\"response\":{\"transactionId\":\"12241094986\",\"payfoneAlias\":\"432432424\",\"phoneNumber\":\"324324324234\",\"lineType\":\"Mobile\",\"carrier\":\"T-Mobile USA\",\"countryCode\":\"US\",\"statusIndex\":\"51\",\"isBaselined\":true,\"score\":1000,\"phoneNumberVelocity\":0,\"portVelocity\":0,\"payfoneTenure\":{\"minimumDate\":\"2024-08-05T23:59:59.000Z\"},\"phoneNumberTenure\":{\"minimumDate\":\"2024-08-05T23:59:59.000Z\"}}}"}
a!localVariables( local!callService: rule!score( customerPhoneNumber: ri!phoneNumber, consentStatus: ri!consentStatus ).result.body, local!jsonArray: a!toJson( value: local!callService, removeNullOrEmptyFields: true ), local!jsonArrays: a!fromJson(local!jsonArray), local!jsonArrays )
Here is the result after testing above code:
[response:{"requestId":"123456","status":0,"description":"Success.","response":{"transactionId":"12241091363","payfoneAlias":"432432424","phoneNumber":"324324324234","lineType":"Mobile","carrier":"T-Mobile USA","countryCode":"US","statusIndex":"51","isBaselined":true,"score":1000,"phoneNumberVelocity":0,"portVelocity":0,"payfoneTenure":{"minimumDate":"2024-08-05T23:59:59.000Z"},"phoneNumberTenure":{"minimumDate":"2024-08-05T23:59:59.000Z"}}}]
Discussion posts and replies are publicly visible
The raw response there doesn't look like standard JSON per se - at the very least it looks as if it's been "nested" in a way that causes most of the double quotes to be "backslash escaped". I'm guessing you need to call a!fromJson() on the initial response and then call a!fromJson() again on the ".response" property of the first call.
This seems to work fine:
Hmm :(
You're passing in the entire "callService" response to a!fromJson. Only local!callService.body (or maybe local!callService.response.body) is actually JSON.
(I can't quite tell based just on your screenshot - if you can't figure it out exaclty, post a screenshot of just the value of local!callService, without calling a!fromJson on it.)
When indexing into body or even trying to do reponse.body, it states it is null. But here is the result of callService
I also tried:
a!localVariables( local!callService: rule!HCP_POST_trustScore( customerPhoneNumber: ri!phoneNumber, consentStatus: ri!consentStatus ), local!jsonArray: a!fromJson(index(local!callService, "body")), a!fromJson(local!jsonArray.response) )
but the error message Im getting is
Expression evaluation error at function a!fromJson [line 6]: The jsonText parameter must not be null or empty.
"body" is not under "local!callService" but under ".result".
Therefore the proper syntax would be a!fromJson(local!callService.result.body) by what I can see here.(Or local!callService.result.body.CensoredResponse even - due to your redactions I'm slightly unclear what the data structure is on that last layer down.)
The usual way to troubleshoot this would be to start with your response (local!callService) and return just that in your rule, then add ".result" to that and make sure it still works, then add ".body" to that and make sure it still works (and looks like valid JSON), then wrap that in a!fromJson() - when you try to bang it all out at once, you're setting yourself up for failure because the issue could be anywhere in those several successive logical steps and it's hard to tell which.
Great point. Followed those steps of troubleshooting, and it returns this result when getting the body of local!callService.result.body
But when trying to convert it to JSON, it states it is not valid.
PS I really appreciate all your guidance and help.
Actually Mike, I got it!! :) Thank you!!!