I tried searching online for help on this but could not find a solution.
I have a job where I need to POST json data by iterating through a number of json files to a web server.
I am using tREST Component which allows me to POST the data if I manually copy and paste it into the HTTP Body field. However I would have thought it be possible to pass through the json data dynamically as a variable to the HTTP Body field.
The layout of my job is as follows:
tFileList >>iterate>> tFileInputDelimited >>iterate>> tRest >>main>> tLogRow
Is anyone able to provide help with this?
You can do this. Where are you getting your JSON from? I will assume that you are getting it from your tFileInputDelimited. If so this will work.
Connect your tFileInputDelimited to a tFlowToIterate component. I am assuming that one of your columns contains your JSON. Lets assume that column is called "myJSON" and the row connecting the tFileInputDelimited to the tFlowToIterate is "row1". Now if you add the following code to your HTTP Body (exactly as shown) it will pass the JSON from your file to your tRest....
If you have to build your JSON from data in your file, then do that first and then pass it (completed in one column) to a tFlowToIterate and follow the same logic.
FYI the tFlowToIterate works by assigning the row.column data to a HashMap using the row.column (name) as the key.
Thanks the first option worked.
My job now looks like this
The tREST now attempts to POST the json data but I get this error message...
"[...]Bad Request","details":"error: instance type (string) does not match any allowed primitive type (allowed: [object])[...]"
Basically it wants an Object not a String type.
Is it possible to convert a String value into an Object?
First of all, you should not have two unconnected subjobs. These need to be linked (probably via an iterate link from the tFlowToIterate to the tRest).
With regard to casting from Object to String, that is easy in Java (so long as the variable IS a String). I assume you are using a globalMap variable. Use the following code....
The "(String)" tells Java to cast (change) the class. This will only work if the two classes are in the same class hierarchy
Sorry, I didn't read your question properly. This *may* be because you have not connected the two subjobs and null is being passed to the Body.
Having said that, it could also be connected to the content-type header. Try connecting the subjobs and run again. You will need to give as much info as you can because web service issues are not as easy to resolve remotely
I have linked the sub jobs and included tREST configuration details in the screenshot.
The content type is set to json. I still receive the same error as before.
I just Googled your error message. It looks like the JSON is being passed OK. That is a JSON error message. I believe there is something wrong with the JSON being sent. Can you show us the JSON?
I have got it working now. I found what the problem was. I needed to remove quotes that were outside the json message and also remove the escaped quotes from the message itself.
I have a similar scenario, could you please help by posting the screenshot of each component.
Talend named a Leader.
Kickstart your first data integration and ETL projects.
Watch the recorded webinar!
Find out how to migrate from one database to another using the Dynamic schema
Learn how to make your data more available, reduce costs and cut your build time
Read about OTTO's experiences with Big Data and Personalized Experiences