Facebook Graph API Batch Request Filtering?

853 views Asked by At

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/ )

https://developers.facebook.com/community/threads/325616225418947/?notif_id=1599002283105969&notif_t=developer_community_forum_thread_update&ref=notif

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&notif_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 {}.

1

There are 1 answers

3
CBroe On BEST ANSWER

The format in which the parameters are supplied is the issue here.

If you were going via the events endpoint directly, then supplying the since 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, specifying since as an additional GET parameter on the same “level” as fields 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 of events or somethingelse by the since value here, that would be ambigous.

So, field expansion syntax needs to be used here:

?fields=events.since(1599036240){id,name,start_time}

This way, that since parameter is explicitly tied to the events endpoint here (and you could specify somethingelse.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.)