Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

POST request with JSON data to tRESTClient component

How can I create POST request with JSON data using tRESTClient component? I can only successfully send XML Document. Should I put JSON data inside XML element? It seems that is the only way to send JSON data. I am using talend 5.5.1.
Labels (5)
35 Replies
Anonymous
Not applicable
Author

What is the 'Consomme' in your tRESTRequest? If you choose 'xml' and your body is in type document, this component will convert json to xml automatically. If you don't want this conversion. You should choose 'JSON' and put your body in type String. In this case, you don't need to check 'Wrap JSON Request'.
Lin LIN
Consultant BI/Talend
Synaltic Group
Anonymous
Not applicable
Author

louislinlin, if he sends the JSON using the string input it will be converted to XML and received via the "body" field by the service. The reason that JSON is converted to XML is so that either JSON or XML can be accepted, but you only have to process one type in the service regardless of the input. 
Sebast, why don't you use a tExtractXMLField instead of a tExtractJSONField component? You will receive XML if you supply JSON to the string input. It will be converted and output by the body field. You *can* wrap your JSON in an XML document using "Wrap JSON Request", but what is the point? That will still have to be extracted before you can use the tExtractJSONField. 
Anonymous
Not applicable
Author

rhall_2.0, if you choose the body type in String, the json will not be converted to xml.
Lin LIN
Consultant BI/Talend
Synaltic Group
Anonymous
Not applicable
Author

Louislinlin, I didn't know about that. I guess that is a hidden gem very much like how to enable query parameters on REST services. Having said that, I generally write services to accept either JSON or XML, so I maybe didn't look for it. Having services receive XML as it is sent, or JSON converted to XML, makes processing the data far easier from my perspective since I don't need to care about how it is sent. But it is useful to know. 
So to solve Sebast's issue all he needs to do is change the "body" type of his tRESTRequest's schema to be String rather than Document. 
Anonymous
Not applicable
Author

So to solve Sebast's issue all he needs to do is change the "body" type of his tRESTRequest's schema to be String rather than Document.

Yes this solved the problem, thanx.
adolitos
Contributor
Contributor

I had this problem trying to connect to sharepoint api.

 

Firstly I have tested my requests against postman:

1) Write my request in postman

0683p000009M19I.png0683p000009M0x4.png

 

2) Click on Code at the top right (previous image)

3) Copy the red marked part

 

0683p000009M19l.png

 

4) If your request is working fine in postman move to talend and write your request there. Past the marked section from the previous picture inside body section at tRest component.

0683p000009M0nW.png

 

5) be happy!

0683p000009M12H.png

 


ev1.png