10-17-2020 08:26 PM - edited 10-17-2020 08:32 PM
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\"}"
10-18-2020 05:38 AM
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.
10-18-2020 05:38 AM
What version of CVP do you have, there was a REST Client bug regarding post w/json a while back...
10-18-2020 05:39 AM
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
10-18-2020 06:35 AM
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
10-18-2020 06:41 AM
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.
10-18-2020 07:15 AM
replace all the \" with apostrophe ' (no back slash)
and remove the \n
10-18-2020 07:21 AM
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.
11-13-2020 06:46 PM
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
11-14-2020 01:59 PM - edited 11-14-2020 02:41 PM
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":{}}
11-14-2020 02:47 PM
11-14-2020 02:54 PM
11-14-2020 03:32 PM
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
11-14-2020 05:29 PM
Try this in the SetValue element. Perhaps it'll omit the quotes.
var obj = {"query":"query {countries{name}}","variables":{}};
JSON.stringify(obj);
11-14-2020 06:09 PM
Validation checks are successful but on debug there are java error on SetValue element
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: