Hi all,
I have to create a Rest Service with method POST. This service, for the moment, hasn't input and returns a JSON that I have set from a file like shown in figures.
I tried this service by Rest Client, but it returns status code "415 Unsupported Media Type".
Someone could show me an example with method post?
thanks
Hi
You have the endpoint that expects HTTP Content-Type set to application/json or application/xml, 415 would be returned if it is set to something else, example, some clients may set a form Content-Type if no Content-Type is set.
HTH, Sergey
Hi, I guess you have 2 options:
- set tRESTClient body type to String and use a tWriteJsonField component
- use tXmlMap to build XML tree and then let tRESTClient auto-convert it to JSON, keep the body type as Document
Cheers, Sergey
Hi Sergey,
I don't use tRestCLient, but I want to use Advanced Rest Client. For this reason, I have to know the format for the JSON to send to Service.
First of all, can you please vote for
https://jira.talendforge.org/browse/TESB-15346 OK, so you have this JSON payload. The 1st thing that needs to be done is to have it mapped to a schema parameter called 'body' - so add a 'body' parameter there of either String or Document type.
If you choose String - it means you need to process it with one of components which can take a JSON string and process it,
If you choose Document - it means tRESTRequest will try to auto-convert JSON into a Document which you can later process with tXMLMap, etc.
In this specific case make sure you set tRESTRequest wrap json sequence property to true to get the auto-conversion working.
Please also make sure Advanced Rest Client sets Content-Type to application/json - one way to check is to enable TRESTRequest to log the incoming requests
HTH, Sergey