cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Ask Me Anything - October 2020

264
Views
5
Helpful
8
Replies
Highlighted
Beginner

CCX Script Editor - Place REST Call Step

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
    }
  }
}
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted

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.

View solution in original post

Highlighted

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" }

View solution in original post

8 REPLIES 8
Highlighted
VIP Mentor

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\" }"

 

 

Highlighted

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\"}"
Highlighted

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.

View solution in original post

Highlighted

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 

 

Highlighted

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 

Highlighted

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" }

View solution in original post

Highlighted

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

Highlighted

I'm happy for you!  Good luck with your project!

Content for Community-Ad