Skip to main content
Question

Question about formatting date in REST collector for JSON body.

  • March 11, 2025
  • 9 replies
  • 36 views

Shawn Cannon
Forum|alt.badge.img

OK I have another REST collector question. My collect section I am using POST with body. The body is JSON and it has to provide the time there (start and end). I was trying `${earliest}` and `${latest}` but it does not seem to work. I think it is expecting the date to be in a certain format. This collector is currently a bash script but I was thinking it would work as a REST collector. The bash script sets and start and end variable like this:start="$(date --date=-1days '+%F %H:%M:%S')"end="$(date --date=last-minute '+%F %H:%M:%S')"How can I do this with the REST collector? Ideas?

9 replies

Shawn Cannon
Forum|alt.badge.img
  • Author
  • Known Participant
  • March 11, 2025

<@U01C35EMQ01&gt; you know of anyone that can help me?


Or use a fallback like this:


Remember that you must set earliest and latest fields in the job config for those variables to be defined


```Earliest: `${C.Time.strftime(new Date((earliest * 1000 || Date.now() - (246060*1000))), "%Y-%m-%d %H:%M:%S")}`Latest: `${C.Time.strftime(new Date((latest * 1000 || Date.now() - (60 * 1000))), "%Y-%m-%d %H:%M:%S")}````


Shawn Cannon
Forum|alt.badge.img
  • Author
  • Known Participant
  • March 11, 2025

If my collect method is POST with body, I do not have any collect parameters. Lets say this is the POST body:{"list": "value", "start": "this need to be earliest", "end": "this needs to be latest" }


Shawn Cannon
Forum|alt.badge.img
  • Author
  • Known Participant
  • March 11, 2025

How can I use what you provided in the POST body?


````{"list": "value", "start": "${C.Time.strftime(new Date((earliest * 1000 || Date.now() - (246060*1000))), "%Y-%m-%d %H:%M:%S")}", "end": "${C.Time.strftime(new Date((latest * 1000 || Date.now() - (60 * 1000))), "%Y-%m-%d %H:%M:%S")}" }````


Shawn Cannon
Forum|alt.badge.img
  • Author
  • Known Participant
  • March 11, 2025

thanks! I will give it a whirl


Shawn Cannon
Forum|alt.badge.img
  • Author
  • Known Participant
  • March 11, 2025

good stuff, it worked. that stuff with time and date javascript is the stuff I need to learn more about