Skip to content

Passing Arrays to the FB API

trdinich edited this page May 13, 2020 · 7 revisions

Passing Arrays to FB

Some API endpoints require you to pass an array, for example the campaigns graph endpoint requires an array for the 'effective_status' parameter. See details here: https://developers.facebook.com/docs/marketing-api/reference/ad-account/campaigns

This means that Facebook is expecting an array literally in the url, not string with comma delimited items.

For raw requests (via Graph Explorer) this works:

act_xxx/campaigns?fields=id,name&effective_status=['ACTIVE','PAUSED']&appsecret_proof=xxx

This does not work:

act_xxx/campaigns?fields=id,name&effective_status=active,paused&appsecret_proof=xxx

^ produces an error: (#100) For field 'campaigns': param effective_status must be an array.

Using Koala

This can be passed to Koala by passing that array as a string literal so that the sanitizer will not change it:

@api.get_object('act_XXX', {fields:[:name, :id], effective_status: "['ACTIVE','PAUSED']"})

Hope this is helpful to someone, took me a bit to get through it. When in double check the raw requests against the graph explorer: Graph Explorer

Clone this wiki locally