Six Stars

MAKE API CALL

Hi All,

In my job i used tHttpRequest component to make request on API

For GET or POST method, i configure my component like bellow by reading parameters from a file.

status.png

Now i need to make PUT method, and this method is not supported by tHttpRequest component.

Like solution, i try tRest component to solve issue.

 

My problem now is how to read my file and put it in a global variable then call it in the field "Corps HTTP" of component tRest to make my request

 

Thank you for help

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: MAKE API CALL

Hi rhall_2_0,

 

I didn't test your solution because i produce my json with tFileoutputJson component which create automatically a json file.

 

But to solve this issue, after creating a json with tFileoutputjson component, i read the the same file with a routine in a tjava component.

This routine read all file's data and put it in a string (globla variable) that i call in tRest component.

 

Thank all for help,

2 REPLIES
Twelve Stars

Re: MAKE API CALL

The tRest is actually simpler and doesn't require that you write to a file. Simply produce your JSON in the same way as before, but do not write it to a file. Connect your component that outputs your JSON to a String, to a tFlowToIterate component. This component will allow you to connect your tRest using an Iterate link. It will also add your value to the globalMap. If the "row" connecting to your tFlowToIterate is called "row1" and your JSON column is called "json", the globalMap will be referenced using this code....

 

((String)globalMap.get("row1.json"))

Simply put that in your HTTP Body field WITHOUT surrounding quotes.

 

You may need to tweak some of your headers. Take a look here for that (https://help.talend.com/reader/iYcvdknuprDzYycT3WRU8w/_N82Hv0ivAnxD69EWaC5rA)

 

 

Rilhia Solutions
Six Stars

Re: MAKE API CALL

Hi rhall_2_0,

 

I didn't test your solution because i produce my json with tFileoutputJson component which create automatically a json file.

 

But to solve this issue, after creating a json with tFileoutputjson component, i read the the same file with a routine in a tjava component.

This routine read all file's data and put it in a string (globla variable) that i call in tRest component.

 

Thank all for help,