cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
8781
Views
10
Helpful
18
Replies

CVP Call Studio Rest_Client - POST body syntax

AlexIancu91604
Level 1
Level 1

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

 

 

 

 

I was able to get this to work in UCCX Script Editor by following the syntax below 

 

 

 

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: \\\"UCCX Testing\\\" }]\\n direction: \\\"outbound\\\"\\n intent: \\\"info\\\"\\n sessionID: \\\"\\\"\\n recipient: [\\n {\\n resourceType: \\\"Patient\\\"\\n telecom: [{ system: \\\"phone\\\", value: \\\"" + REST_callbacknumber + u"\\\", use: \\\"mobile\\\" }]\\n }\\n ]\\n }\\n) {\\n identifier {\\n value\\n }\\n}\\n}\\n\"}"

 

 

 

 

18 Replies 18

janinegraves
Spotlight
Spotlight

When I enter your json into jsonpathfinder dot com - I get this error


There seems to be a problem with your JSON.
Error message: JSON.parse: unexpected character at line 1 column 1 of the JSON data


I've never seen valid json that has the format you posted.

What version of CVP do you have, there was a REST Client bug regarding post w/json a while back...

It'll also be helpful if you log the element data named status_code and response_body so we can see what the return error message actually contains

Janine - thanks for the reply. Here is more information 

 

JSON code that is valid by checking multiple tools but does not pass validation in call studio

{"query":"mutation {\n  createCommunication(communication: {status: \"needs_delivery\", priority: \"\", category: \"\", reasonCode: \"wayfinding\", topic: \"\", note: \"\", medium: \"sms\", payload: [{contentString: \"Hello World\"}], direction: \"outbound\", intent: \"info\", sessionID: \"\", recipient: [{resourceType : \"Patient\", telecom: [{ system : \"phone\", value: \"9171234567\", use: \"mobile\"}]}]}) {\n    identifier {\n      value\n    }\n    payload {\n      value\n    }\n  }\n}\n"}

Error on validation - it feels that is related to the area in regards to response values at the end 

Action Element: Rest_Client_01	Configuration error: The value of the setting "Body" contains substitution errors: "{\n      value\n}": Invalid Key: \n      value\n

You didn't say what version, but Janine might be right on the money as always, the brackets may be the problem if you're hitting this bug.

https://bst.cloudapps.cisco.com/bugsearch/bug/CSCve44607

replace all the \" with apostrophe '  (no back slash)

and remove the \n

The workaround may be to use the Set Value element to assign your json query into a LocalVariable. Then use the value of that LocalVariable in the rest client element Body Setting.

 

 

Janine,

Sorry for my late response but I've tried everything and either it does not pass validation or the Set Value element does not accept the code. I am running version 11.6.1 and was wondering if anyone can post an example of Rest_Client post using Application/JSON 

 

I created a Cisco case and the code provided gives me an error on transport from all rest clients used 

 

I appreciate any input on this issue 

I think I might've figured out what is happening (not to be mistaken with the issue being resolved) and why I am getting errors on validation. From the example below I get validation errors due to (name) which I guess Call Studio thinks its a substitution, I tried using the Set_Value step but I am running into the same issue 

 

Validation error: Project Location Description Creation time Id
Countries Action Element: Rest_Client_01 Configuration error: The value of the setting "Body" contains substitution errors: "{name}": Invalid Key: name 1605391251997 752

 

Postman troubleshooting with the info below is successful 

 

URL https://countries.trevorblades.com
HTTP header Content-Type application/json
RAW body {"query":"query {countries{name}}","variables":{}}

 

In the SetValue element, be sure that your json string is between single quotes, and no line breaks.
In the Rest element, in the Body, just enter the local variable {LocalVar.varname}
Mine validates...

you definitely have to assign the json into a local variable in set value element, and be sure it's surrounded by single quotes, and no line breaks.
In the Rest element, in the Body, just select the value of your local variable {LocalVar.varname}
Mine validates..

Janine, you are 100% correct adding the code between single quotes helps with the validation but it appears that Call Studio is sending these single quotes as well and I get a bad request . After you mentioned this I added tried 

'{"query":"query {countries{name}}","variables":{}}' in Postman and I am getting a bad request as well
 
See attached app
 
 

Try this in the SetValue element. Perhaps it'll omit the quotes.

 

var obj = {"query":"query {countries{name}}","variables":{}};

JSON.stringify(obj);

 

 

 

 

 

 

Validation checks are successful but on debug there are java error on SetValue element cvp.PNG

Getting Started

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: