Returning JSON from /api/v1/Agents/CRMScript/ExecuteScriptByIncludeId ?

lock
push_pin
done
Answered
3

Hi,

when using the API method /api/v1/Agents/CRMScript/ExecuteScriptByIncludeId, how can we return JSON, and not a quoted string?

Here is an example of how I'm calling the method;

When calling that method we get this response back. It says Content-Type should be JSON, but the text I printed in the CRMScript is wrapped in two quotes.

I expected the content to be formatted like this instead:

{'hello':'world'}

Inside the CRMScript I just print a text, like this - should I have done anything different here?

#setLanguageLevel 3;

print("{'hello':'world'}");

 

 

23 Sep 2022 | 01:44 PM

All Replies (3)

The same happens for REST endpoints as well (not just Agents API).

/v1/CRMScript/95/Execute
19 Oct 2022 | 09:15 AM

You are literally telling the script to return a string, but what you are wishing for is a printJson("") that strips the string quotes. Correct?

One could presume to say/think, this use case is one that CRMScript was never intended for, and therefore shouldn't be attempted. 

19 Oct 2022 | 09:55 AM

Well yes, I wish I was able to control exactly what it returned, yes. It should return the string I print, without putting it in quotes.

By using the "Accept" header in the request I can control wether the "Content-Type" header returned is either "application/json" or "application/xml", but from the script I'm unable to return valid JSON or XML.

printJson("") could do the job, but honestly print("") should just have worked. That's what we use in webservices created with plain CRMScript for returning JSON.

The scenario came up now because I want to funnel the authentication via the standard REST-API instead of having to roll our own authentication in plain CRMScript.

19 Oct 2022 | 10:52 AM

Add reply