Discussion:
POST JSON body using HTTP Client Connector
(too old to reply)
Diana
2017-09-11 19:41:37 UTC
Permalink
Raw Message
Hello,

I am using the HTTP Client Connector to send http body in JSON. I have noticed that if I use "File to HTTP Body" in the Connection configuration tab, that works. But I do not want to send a file every time. Instead, I want to be able to script it as part of the workflow. I tried to do it with the output map to http.body. I have the following simple code:

var jsonbody = { "UserID" : "66203" };
ret.value = toJson(jsonbody);

Looking at the error message I received back, it doesn't appear the body was send over or understood.

Any suggestion is appreciated.

Thanks,
Diana
yn2000
2017-09-12 19:29:32 UTC
Permalink
Raw Message
I believe the answer is something like: "..because you already construct your own JSON body, then you do not need to transform again."

try something like this:
var jsonbody = "{ \"UserID\": \"66203\" }";
ret.value = jsonbody;

Rgds. YN.
Diana
2017-09-12 20:01:41 UTC
Permalink
Raw Message
Post by Diana
Hello,
I got this to work. In the configuration tab, do not select any parser. Before I had it set to JSON (because that seemed logical). Among google search results, I saw that someone mentioned that the Parser doesn't really work. So I removed the parser and now it works.
Post by Diana
var jsonbody = { "UserID" : "66203" };
ret.value = toJson(jsonbody);
Looking at the error message I received back, it doesn't appear the body was send over or understood.
Any suggestion is appreciated.
Thanks,
Diana
Eddie Hartman
2017-09-12 20:15:20 UTC
Permalink
Raw Message
Post by Diana
Post by Diana
Hello,
I got this to work. In the configuration tab, do not select any parser. Before I had it set to JSON (because that seemed logical). Among google search results, I saw that someone mentioned that the Parser doesn't really work. So I removed the parser and now it works.
Post by Diana
var jsonbody = { "UserID" : "66203" };
ret.value = toJson(jsonbody);
Looking at the error message I received back, it doesn't appear the body was send over or understood.
Any suggestion is appreciated.
Thanks,
Diana
The Parser works fine, it's just that you might not always be getting an expected payload in return. That's why it's best to do the parsing after your Connector.

And for a tutorial on how to construct your own hierarchical data (xml or json), have a look at this old vid:


And Hierarchical Entry blog posts:
Here is part one (written many moons ago): http://www.tdiingoutloud.com/2013/09/json-and-xml-tutorial-part-1.html
and then (forgive the numbering :P)
http://www.tdiingoutloud.com/2015/02/json-and-xml-tutorial-part-2.html
http://www.tdiingoutloud.com/2016/02/json-and-xml-tutorial-part-2-xml-example.html
http://www.tdiingoutloud.com/2016/11/json-and-xml-tutorial-part-4-json.html
http://www.tdiingoutloud.com/2016/11/json-and-xml-tutorial-part-5.html This one about scripting a connector to hide the complexity of the calls
http://www.tdiingoutloud.com/2016/11/json-and-xml-tutorial-part-6-making.html
Loading...