We have updated our Terms of Service, Code of Conduct, and Addendum.

Dynamic Date in API URL

Tony Reinke - Cribl
Tony Reinke - Cribl Posts: 134 admin
edited September 2023 in General Discussions

I am finally getting around to converting some of my crontabs to Cribl Stream API sources. I am looking to have a dynamic date/time variable in the URL. The date would need to be the date from yesterday.

Today's Date/Time: 2023-08-11T08:00:00.00Z
Needed Date/Time: 2023-08-10T08:00:00.00Z

Using %3C to do before date. I need the `dateLastValue` field to change.

Example URL:

Need something like:



  • Ryan Hennessy
    Ryan Hennessy Posts: 21 ✭✭

    I assumed you wanted to convert your current cronjob to a REST Collector source when I complied with my answer. The other assumption is that you would like the date/time field to be precisely 24 hours before the job run. If that is not the case, please provide an updated comment.

    Using the content from your example, you could build out a dynamic URL via some string concatenation and some work from the Date function. Pasting following into the "Collect URL" field of the REST Collector should provide you with what you want.

    "https://web.site.url/api/v3/discussions?dateLastValue=%3C" + (new Date((new Date()).valueOf() - 1000*60*60*24).toISOString()).replace(/:/g,"%3A") + "&status=true&field1=false&field2=true&page=1&limit=30"