The problem: My batch request returns passed group events and the current batch request will scale badly with users creating future events.
I have the following batch request:
{
"batch": [
{
"method": "GET",
"relative_url": "me"
},
{
"method": "GET",
"relative_url": "me/groups?fields=events{id,name,start_time}"
},
{
"method": "GET",
"relative_url": "me/accounts"
}
],
"include_headers": "false"
}
This request will fetch (among other things) all user group events. I only need upcoming events.
Question: How can I apply filters in a Batch request?
The following query URL is not working when used as a relative_url:
me/groups?fields=events{id,name,start_time}&since=1599036240
The filter parameter is:
since=MY_CURRENT_TIME
The documentation I read wasn't of much help. I don't even know if it is possible to add filters (fields) to a batch request. ( https://developers.facebook.com/docs/graph-api/making-multiple-requests/ )
I also asked the same question on the FBs dev forum with no answer (so far): https://developers.facebook.com/community/threads/325616225418947/?notif_id=1599002283105969¬if_t=developer_community_forum_thread_update&ref=notif
UPDATE 1 (02.09.2020.):
@CBroe pointed out that the Batch Requests URLs should work the same as standalone requests. This leads me to believe that my relative_url
does not filter properly. Testing:
me/groups?fields=events{id,name,start_time}&since=1599036240
with output:
events": {
"data": [
{
"id": "324058568947509",
"name": "Testing FB Graph API",
"start_time": "2020-08-25T15:00:00+0200"
}
],
conforms that filtering does not work with &since=1599036240
and the URL containing {}
.
The format in which the parameters are supplied is the issue here.
If you were going via the
events
endpoint directly, then supplying thesince
parameter this way would work:/group-id/events?since=…
But you are not using that format, you are going via
me/groups?fields=events
- and in that case, specifyingsince
as an additional GET parameter on the same “level” asfields
won’t work.The reason is that you could be requesting data from more than one endpoint this way -
?fields=events,somethingelse&since=…
- do we want to filter the results ofevents
orsomethingelse
by thesince
value here, that would be ambigous.So, field expansion syntax needs to be used here:
This way, that
since
parameter is explicitly tied to theevents
endpoint here (and you could specifysomethingelse.since(…)
differently here for a second endpoint.)(And the parameters need to be in this order,
events{id,name,start_time}.since(…)
would give a syntax error, the field list first with{…}
and then the dot syntax isn’t understood by the query parser.)