Facebook Marketing API - time_range

If you are doing this in the Graph API Explorer, it should be like below:

  1. Work: time_range={since:'2021-05-01',until:'2021-05-05'}
  2. NOT Work: time_range={'since':2021-05-01,'until':2021-05-05}

I get #2 syntax from Facebook's document itself :|


Another alternative is to pass the time_range object as below if you don't want to encode the URL and want to keep the URL clean.

Facebook is smart enough to parse the URL and set the correct time_range.

https://httpbin.org/get?time_range[since]=2019-08-10&time_range[until]=2019-09-09

I imagine you've found the answer by now but this could help someone else as from experience the documentation isn't always the most friendly to jump into.

You'll need to format it as a time_range object, the example object below is from that page of the documentation you included. It's essentially just an object with 2 properties- since and until.

{'since'=>YYYY-MM-DD,'until'=>YYYY-MM-DD}

So from the example URL you're using, rather than setting the since and until values using individual parameters, the time range would be set like this (I've URL encoded the object):

time_range=%7B%22since%22%3A%22YYYY-MM-DD%22%2C%22until%22%3A%22YYYY-MM-DD%22%7D