10-14-2020 05:45 AM
I am trying to post data to an external server but I can't seem to get the body of the request to work. I used multiple tools such as Postman and I am getting the result I need but all these tools understand multiple programming languages
Here is what I need to post in the body
mutation { createCommunication( communication: { status: "needs_delivery" priority: "" category: "" reasonCode: "wayfinding" topic: "" note: "" medium: "sms" payload: [{ contentString: "Test" }] direction: "outbound" intent: "info" sessionID: "" recipient: [ { resourceType: "Patient" telecom: [{ system: "phone", value: "646XXXXXXX", use: "mobile" }] } ] } ) { identifier { value } } }
Solved! Go to Solution.
10-14-2020 10:33 AM - edited 10-14-2020 10:33 AM
You should follow the API documentation to format your JSON data, or if that doesn't exist, just check out json.org. You would need something more like this:
u"{ \"status\" : \"needs delivery\", \"reasoncode\" : \"wayfinding\" }"
Where multiple keyvalue pairs are separated by a comma. This is not a UCCX specific issue however, it's a JSON data format issue.
10-15-2020 02:28 PM
u"{ \"value\" : \"" + REST_callerID + u"\" }"
All the quoting sure does make it confusing, but hopefully the above example helps you understand how to slide a variable into the middle of your String. I did this by creating two Strings, and concatenating them with the variable in the middle. I tried to pair up the quotes by using different color pairs: String 1 is Red and String 2 is Blue, with the variable concatenation in Green.
The end result would be:
{ "value" : "6461234567" }
10-14-2020 07:29 AM - edited 10-14-2020 07:38 AM
Gah, I wrote a bunch of stuff and then the forum software threw an error when I submitted my reply and now it's lost.
Here's an abridged version: You need double quoted key names in JSON, and you need escaped double quotes in a UCCX String variable. Send it in the Body of the Make REST Call step.
u"{ \"name\" : \"anthony\" }"
10-14-2020 08:00 AM
Anthony - thanks for helping me on this
### I started with this logic u"{\"status\":\"needs delivery\"}{\"reasoncode\":\"wayfinding\"}" ### Am I going in the right direction when multiple entries and based on the example you sent? u"{ \"status\" : \"needs delivery\"}{ \"reasoncode\" : \"wayfinding\"}"
10-14-2020 10:33 AM - edited 10-14-2020 10:33 AM
You should follow the API documentation to format your JSON data, or if that doesn't exist, just check out json.org. You would need something more like this:
u"{ \"status\" : \"needs delivery\", \"reasoncode\" : \"wayfinding\" }"
Where multiple keyvalue pairs are separated by a comma. This is not a UCCX specific issue however, it's a JSON data format issue.
10-15-2020 11:55 AM - edited 10-15-2020 12:01 PM
Anthony - thanks for providing an example on how the data should be formatted. This helped me understand that I was going into the wrong direction and instead of adding multiple keyvalues pairs I realized that HTTP body is technically a single value. I used https://tools.knowledgewalls.com/online-multiline-to-single-line-converter to convert from multiline to a single line and added the needed formatting for UCCX (based on your example)
u"{\"query\":\"# Write your query or mutation here\\nmutation {\\n createCommunication(\\n communication: {\\n status: \\\"needs_delivery\\\"\\n priority: \\\"\\\"\\n category: \\\"\\\"\\n reasonCode: \\\"wayfinding\\\"\\n topic: \\\"\\\"\\n note: \\\"\\\"\\n medium: \\\"sms\\\"\\n payload: [{ contentString: \\\"Test\\\" }]\\n direction: \\\"outbound\\\"\\n intent: \\\"info\\\"\\n sessionID: \\\"\\\"\\n recipient: [\\n {\\n resourceType: \\\"Patient\\\"\\n telecom: [{ system: \\\"phone\\\", value: \\\"646XXXXXXX \\\", use: \\\"mobile\\\" }]\\n }\\n ]\\n }\\n) {\\n identifier {\\n value\\n }\\n}\\n}\\n\"}"
Now that Place REST Call step works as expected I tried to use a String variable for the phone number within the HTTP body (replacing 646XXXXXXX) but for some reason most likely I am not adding it correctly is not working. I tried String.valueOf(REST_callerID) which is a variable that is populated before the POST but it doesn't work
Thanks again for the help you really helped understand how the syntax should be created
10-15-2020 12:15 PM
Anthony - your example helped me understand some of the logic and now my Place REST Call works as expected. I was going down the wrong path on having multiple keyvalue pairs and realized that HTTP body is a single value with correct formatting. I went to https://tools.knowledgewalls.com/online-multiline-to-single-line-converter and coberted multiline into single line and added the using your example I was able to have an accepted syntax
u"{\"query\":\"# Write your query or mutation here\\nmutation {\\n createCommunication(\\n communication: {\\n status: \\\"needs_delivery\\\"\\n priority: \\\"\\\"\\n category: \\\"\\\"\\n reasonCode: \\\"wayfinding\\\"\\n topic: \\\"\\\"\\n note: \\\"\\\"\\n medium: \\\"sms\\\"\\n payload: [{ contentString: \\\"Test\\\" }]\\n direction: \\\"outbound\\\"\\n intent: \\\"info\\\"\\n sessionID: \\\"\\\"\\n recipient: [\\n {\\n resourceType: \\\"Patient\\\"\\n telecom: [{ system: \\\"phone\\\", value: \\\"646XXXXXXX \\\", use: \\\"mobile\\\" }]\\n }\\n ]\\n }\\n) {\\n identifier {\\n value\\n }\\n}\\n}\\n\"}"
My challenge is now to take a String variable (phone number) and replace the 646XXXXXXX withing the HTTP body. I tried String.valueOf(REST_callerID) where REST_callerID is a variable available in the script before Place REST Call
Thanks again for your input
10-15-2020 02:28 PM
u"{ \"value\" : \"" + REST_callerID + u"\" }"
All the quoting sure does make it confusing, but hopefully the above example helps you understand how to slide a variable into the middle of your String. I did this by creating two Strings, and concatenating them with the variable in the middle. I tried to pair up the quotes by using different color pairs: String 1 is Red and String 2 is Blue, with the variable concatenation in Green.
The end result would be:
{ "value" : "6461234567" }
10-16-2020 08:22 PM
Anthony I was able to get everything to work based on your input - thanks for the help on this issue and for all the other threads that helped myself and others understand UCCX
10-19-2020 07:24 AM
I'm happy for you! Good luck with your project!
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: