How to add a variable to pass date parameters in tRESTClient component

One Star

How to add a variable to pass date parameters in tRESTClient component

Hi,
I am using Talend open studio for data integration 5.4 for my data integration needs. I am testing to get data from api service using tRESTclient component. For webservice parameters, I can pass static dates. But if I want to automate this job on daily basis, I want to use a variable which will get the today's date and can be passed as parameter to webservice. I am trying to figure out how can I use a variable to pass date parameters to tRESTClient component. Can anyone please help me?

Thanks,
Gowri
Community Manager

Re: How to add a variable to pass date parameters in tRESTClient component

Hi
You can specify the parameter in the Query parameters table, see my screenshot, I use the built-in function TalendDate.getCurrentDate() to the current date as the value of mydate parameter.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to add a variable to pass date parameters in tRESTClient component

Thanks Shong for the reply. This really works. I also a need to pass output of one the tRESTClient as a query parameter to next tRESTClient. How do you do that?
In my example, I make a call to get job id. Then I need to pass that job id to second tRESTClient as a query parameter. How can I replicate this one?
Thanks,
Gowri
Community Manager

Re: How to add a variable to pass date parameters in tRESTClient component

Hi
tRestClient returs a document, link the response to a tXMLMap to extract the value you want from the document, and pass it to another tRestClient, the job design looks like:
tRestClient_1--Response-->tXMLMap---main(row1)---tFlowToIterate---tRestClient_2
on tRestClient_2, set the query parameter with the value such as (String)globalMap.get("row1.jobId")
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to add a variable to pass date parameters in tRESTClient component

Hi Shong,
I tried to create a workflow like you mentioned. I am not able to connect tFlowtoIterate - Iterate to tRestClient_2. I don't see tFlowToIterate - Main to connect to tRestClient.
Community Manager

Re: How to add a variable to pass date parameters in tRESTClient component

Hi
It was a wrong job design, tRestClient don't accept an iterate link as input flow. The solution is to store the value returned by tRestClient_1 to a context variable or global variable for use later; In the next subjob, tRestClient use the context variable or global variable as the parameter value.
tRestClient_1--Response-->tXMLMap---main--tJavaRow
|
onsubjobok
|
tRestClient_2
on tJavaRow, store the value to a context variable, for example:
context.jobId=input_row.jobId;
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to add a variable to pass date parameters in tRESTClient component

Hi,
I have a PHP script which does HTTP post request to get data from external API service . I am trying to migrate that script to Talend using tRestClient to do a http post request with content type as JSON. Script has following callobject
$callobj = array(
'method' => $method_name,
'params' => array( 'partner_id' => $partner_id,
'tms' => $tms,
'sig' => $sig,
'date' => 'yyyy-mm-dd', // Only one date allowed per api call
'attribution' => 'conversion', // 'conversion' or 'click', determines whether to filter date by view/click or by conversion
'timezone' => 'UTC',
'fields' => array( 'site_id', 'type', 'name', 'conversion_datetime', 'action_type','client_user_id'),
)
);
In tRestClient component I have set up following based on above code snippet
I have given the url, HTTP Method - POST, Content Type -> JSON, Accept_type -> JSON
In query parameters
"method" - "method_name"
"params" -"partner_id=X$partner_id,tms=$tms,sig=$sig,date=yyyy-mm-dd,attribution=click,timezone=PST,fields=site_id,metrics=fbspend"
But it is not working. Is this kind of POST request supported in Talend? Is there way to pass this parameters? Can you please help me?
Thanks,
Gowri

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch