<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic tRest with dynamic body in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/tRest-with-dynamic-body/m-p/2243506#M29962</link>
    <description>&lt;P&gt;Hey ,&amp;nbsp;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I want to create a flow to get data from API ,to made that , I need to create export definition first.&lt;BR /&gt;In export definition I need to put from what date range , data need to be prepared.&lt;/P&gt; 
&lt;P&gt;So I thought that the simplest way to archive that will be use tJavaRow component where inside&amp;nbsp;I will do that code :&lt;/P&gt; 
&lt;PRE&gt;String todayDate = TalendDate.formatDate("yyyy-MM-dd", new Date());
String yesterday = TalendDate.addDate(todayDate,"yyyy-MM-dd",-1,"dd");
String Definition = "{\"name\": \"Bulk Activity Export - Email Clickthrough\",\"fields\": {\"ActivityDate\": \"{{Activity.CreatedAt}}\",\"ActivityType\": \"{{Activity.Type}}\",\"EmailAddress\": \"{{Activity.Field(EmailAddress)}}\",\"EmailWebLink\": \"{{Activity.Field(EmailWebLink)}}\",\"SubjectLine\": \"{{Activity.Field(SubjectLine)}}\"},\"filter\": \"'{{Activity.Type}}' = 'EmailClickthrough' AND '{{Activity.CreatedAt}}' &amp;gt;= '" + &lt;FONT color="#FF0000"&gt;yesterday&lt;/FONT&gt; + "' AND '{{Activity.CreatedAt}}' &amp;lt; '" + &lt;FONT color="#FF0000"&gt;todayDate&lt;/FONT&gt; + "'\"}";
globalMap.put("Definition", Definition);&lt;/PRE&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;But then I cannot pass "Definition" value to the tRest component.&lt;/P&gt; 
&lt;P&gt;Current , my flow looks like :&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EloquaBulk.png" style="width: 579px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MA4e.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/131179iEF32A8C225B5502B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MA4e.png" alt="0683p000009MA4e.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;For now , I've get all values from tSetGlobalVar component , and for static export definition works without no problem.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;How to resolve that problem ?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thank you ,&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Lucjan&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Mar 2020 09:08:39 GMT</pubDate>
    <dc:creator>lucTalend</dc:creator>
    <dc:date>2020-03-11T09:08:39Z</dc:date>
    <item>
      <title>tRest with dynamic body</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tRest-with-dynamic-body/m-p/2243506#M29962</link>
      <description>&lt;P&gt;Hey ,&amp;nbsp;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I want to create a flow to get data from API ,to made that , I need to create export definition first.&lt;BR /&gt;In export definition I need to put from what date range , data need to be prepared.&lt;/P&gt; 
&lt;P&gt;So I thought that the simplest way to archive that will be use tJavaRow component where inside&amp;nbsp;I will do that code :&lt;/P&gt; 
&lt;PRE&gt;String todayDate = TalendDate.formatDate("yyyy-MM-dd", new Date());
String yesterday = TalendDate.addDate(todayDate,"yyyy-MM-dd",-1,"dd");
String Definition = "{\"name\": \"Bulk Activity Export - Email Clickthrough\",\"fields\": {\"ActivityDate\": \"{{Activity.CreatedAt}}\",\"ActivityType\": \"{{Activity.Type}}\",\"EmailAddress\": \"{{Activity.Field(EmailAddress)}}\",\"EmailWebLink\": \"{{Activity.Field(EmailWebLink)}}\",\"SubjectLine\": \"{{Activity.Field(SubjectLine)}}\"},\"filter\": \"'{{Activity.Type}}' = 'EmailClickthrough' AND '{{Activity.CreatedAt}}' &amp;gt;= '" + &lt;FONT color="#FF0000"&gt;yesterday&lt;/FONT&gt; + "' AND '{{Activity.CreatedAt}}' &amp;lt; '" + &lt;FONT color="#FF0000"&gt;todayDate&lt;/FONT&gt; + "'\"}";
globalMap.put("Definition", Definition);&lt;/PRE&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;But then I cannot pass "Definition" value to the tRest component.&lt;/P&gt; 
&lt;P&gt;Current , my flow looks like :&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EloquaBulk.png" style="width: 579px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MA4e.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/131179iEF32A8C225B5502B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MA4e.png" alt="0683p000009MA4e.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;For now , I've get all values from tSetGlobalVar component , and for static export definition works without no problem.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;How to resolve that problem ?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thank you ,&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Lucjan&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 09:08:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tRest-with-dynamic-body/m-p/2243506#M29962</guid>
      <dc:creator>lucTalend</dc:creator>
      <dc:date>2020-03-11T09:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: tRest with dynamic body</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tRest-with-dynamic-body/m-p/2243507#M29963</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;first of all, some tips:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;String todayDate = TalendDate.formatDate("yyyy-MM-dd", new Date());
String yesterday = TalendDate.addDate(todayDate,"yyyy-MM-dd",-1,"dd");

//you can use following Talend methods
String todayDate = TalendDate.getDate("yyyy-MM-dd");
String yesterday = TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd");
//which is equivalent to
String yesterday = TalendDate.addDate(new Date(),-1,"dd");&lt;/PRE&gt; 
&lt;P&gt;Now, regarding your question :&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;If I understand correctly, you want to produce the json changing only the dates according to the current day?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;In that case, you could directly put some java code in the tRest body :&lt;/P&gt; 
&lt;PRE&gt;"{\"name\": \"Bulk Activity Export - Email Clickthrough\",\"fields\": {\"ActivityDate\": \"{{Activity.CreatedAt}}\",\"ActivityType\": \"{{Activity.Type}}\",\"EmailAddress\": \"{{Activity.Field(EmailAddress)}}\",\"EmailWebLink\": \"{{Activity.Field(EmailWebLink)}}\",\"SubjectLine\": \"{{Activity.Field(SubjectLine)}}\"},\"filter\": \"'{{Activity.Type}}' = 'EmailClickthrough' AND '{{Activity.CreatedAt}}' &amp;gt;= '" + TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd")+ "' AND '{{Activity.CreatedAt}}' &amp;lt; '" + TalendDate.getDate("yyyy-MM-dd")+ "'\"}";&lt;/PRE&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;However, it will be hard to maintain as the body grows.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I would prefer to use something like this :&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;tFixedFlowInput -row-&amp;gt; tWriteJSONField -row-&amp;gt; tFlowToIterate -iterate-&amp;gt; tRest ...&lt;/PRE&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;In the tFixedFlowInput, you create all the required data for the json (name, fields, and so one) with correct values.&lt;/P&gt; 
&lt;P&gt;You then create your JSON with the tWriteJSONField.&lt;/P&gt; 
&lt;P&gt;The tFlowToIterate is used to put the JSON in globalMap and you'll use this in your tRest.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;And if your "Definition" comes from a database, you can replace the tFixedFlowInput with whatever data source you nedd.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 12:51:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tRest-with-dynamic-body/m-p/2243507#M29963</guid>
      <dc:creator>lennelei</dc:creator>
      <dc:date>2020-03-11T12:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: tRest with dynamic body</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tRest-with-dynamic-body/m-p/2243508#M29964</link>
      <description>Thanks 
&lt;A href="https://community.qlik.com/s/profile/0053p000007LMbuAAG"&gt;@lennelei&lt;/A&gt; - this export definition will be the same , only dates need to be changed - so your solutions is great !
&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Mar 2020 15:12:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tRest-with-dynamic-body/m-p/2243508#M29964</guid>
      <dc:creator>lucTalend</dc:creator>
      <dc:date>2020-03-13T15:12:05Z</dc:date>
    </item>
  </channel>
</rss>

