facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
838 stars 518 forks source link

Updating the status on an AdSet #137

Closed joshhornby closed 9 years ago

joshhornby commented 9 years ago

I am trying to update the status on an AdSet - I am following the the official docs but I get the following error when trying to run the code:

InvalidArgumentException in FieldValidation.php line 44 :status is not a field of FacebookAds\Object\AdSet

This is because the status field is not in the returned object, or in the AdSetFields class (https://github.com/facebook/facebook-php-ads-sdk/blob/master/src/FacebookAds/Object/Fields/AdSetFields.php)

Can you let me know how I update the status on the AdSet?

Thanks

pruno commented 9 years ago

@joshhornby

The code on that documentation page has not been properly update yet. We are working on it. In the meantime, here is the right one:

use FacebookAds\Object\AdSet;

$adset = new AdSet('<AD_SET_ID>');
$adset->update(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
));

To read the status:

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;

$adset = new AdSet('<AD_SET_ID>');
$adset->read(array(
  AdSetFields::CONFIGURED_STATUS,
  AdSetFields::EFFECTIVE_STATUS,
));

Hope this helps

joshhornby commented 9 years ago

@pruno Perfect. Thanks for your help :)