Unlike targeting a custom audience
, it seems impossible to create an ad targeting a saved audience
using Facebook Ads API. Can someone confirm that is the case? What would be a workaround? This is the error I'm getting:
Error #100: Param targeting[custom_audiences][id] must be a valid custom audience id
There is a difference between a saved audience
and a custom audience
. A saved audience
is an audience you manually create specifying age range, geographic region and interests. While a custom audience
is a list of customers you gathered (uploaded or visitors or your site etc). You can create these audiences manually through the Ads Manager interface:
Using Graph API Explorer, one can retrieve saved audiences
as follow:
act_1234567890/saved_audiences
Using Graph API Explorer, one can retrieve custom audiences
as follow:
act_123456789/customaudiences
Note that 123456789
is not my real account number. I changed it for security reasons.
So, I can retrieve IDs for both custom audiences
and saved audiences
and creating an ad targeting a custom audience
works fine, unlike targeting a saved audience
which gives the above error message.
A cumbersome workaround could be to save the flexible_spec
of each saved audience
locally and use that spec when creating ads. The problem with that is that some targeting segments
become invalid (Facebook decides to discontinue some segments at random times) which causes Facebook Ads API to hickup. Additionally, this means I constantly need to keep saved audiences
in sync with my local copy. Unless of course I retrieve the targeting
of a saved audience
on the fly and re-use it, each time I create an ad resulting in yet another API request.
I figured it out myself. It seems impossible to directly target a saved audience
unlike a custom audience
, which is odd. What I did is retrieve the targeting
from the saved audience first and reuse that targeting when creating the ad.
Here you see a screenshot of the official documentation showing only custom audiences
and lookalike audiences
can be targeted.
Retrieving targeting
from saved audience
(with Facebook PHP SDK):
$api = Api::instance();
use FacebookAds\Http\Request;
$response = $api->call(
"/987654321", 'GET',
array('fields'=>'targeting')
);
$audience = $response->getContent();
With 987654321 as the saved audience ID.
Then copy that targeting to the ad (with Facebook PHP SDK):
use FacebookAds\Object\Targeting;
use FacebookAds\Object\Fields\TargetingFields;
$targeting = new Targeting();
$targeting->setData($audience['targeting']);
The disadvantage of this technique is that the ad won't be updated when the saved audience
is updated and that it requires an extra API call which slows down the creation of the ad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With