Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

How do i set parameters of rest api in InvokeHTTP of NiFi?

avatar
New Contributor

I want to filter my rest api with date range. The rest api has dateFrom and dateTo parameters. I want to set dateFrom to 5 days ago and dateTo to now. How do i set the parameters in NiFi ?

My api looks like the below URL:

https://api.aa/reports/api/order_report/?format=json&dateFrom=&dateTo=

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi,

Not sure how you get the URL but if its hard coded in the InvokeHttp Remote URL property , then you can use expression language to set up your parameters as follows:

 

${literal('https://api.aa/reports/api/order_report/?format=json&dateFrom=#DATEFROM&dateTo=#DATETO'):
  replace('#DATEFROM',${now():format('yyyy-MM-dd')}):
  replace('#DATETO',${now():toNumber():minus(432000000):format("yyyy-MM-dd")})}

 

Notice:

- you can set the date format as desired, in my case I assumed that its in yyyy-MM-dd format.

- To subtract 5 days from the current date you have to convert the date to number , then subtract 5 days in milliseconds (1day = 86,400,000 mls ).

Hope that helps, if it does please accept solution.

Thanks

View solution in original post

1 REPLY 1

avatar
Super Guru

Hi,

Not sure how you get the URL but if its hard coded in the InvokeHttp Remote URL property , then you can use expression language to set up your parameters as follows:

 

${literal('https://api.aa/reports/api/order_report/?format=json&dateFrom=#DATEFROM&dateTo=#DATETO'):
  replace('#DATEFROM',${now():format('yyyy-MM-dd')}):
  replace('#DATETO',${now():toNumber():minus(432000000):format("yyyy-MM-dd")})}

 

Notice:

- you can set the date format as desired, in my case I assumed that its in yyyy-MM-dd format.

- To subtract 5 days from the current date you have to convert the date to number , then subtract 5 days in milliseconds (1day = 86,400,000 mls ).

Hope that helps, if it does please accept solution.

Thanks