I'm trying to create an ad using the Facebook Ads API. So, far I've already created the Ad Set, Ad Creative and Campaign but, when I use the following code to create an ad group, I'm receiving Invalid Parameter exception. Please suggest me if I've any error in the following code.
$campaignId = "xxx";
$appId= "xx";
$ci = "xxx";
$accountId = "xxx";
$appSecret= "xxx";
$accessToken= "xxx";
Api::init($appId, $appSecret, $accessToken);
$api = Api::instance();
$adgroup = new AdGroup(null, $accountId);
$adgroup->setData(array(
AdGroupFields::CREATIVE =>
array('creative_id' => $ci),
AdGroupFields::NAME => 'My First AdGroup',
AdGroupFields::CAMPAIGN_ID => $campaignId,
AdGroupFields::ADGROUP_STATUS => AdGroup::STATUS_PAUSED,
));
$adgroup->create();
The error I receive:
Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter' in /var/www/fb/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Exception/RequestException.php:137 Stack trace: #0 /var/www/fb/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Client.php(216): FacebookAds\Http\Exception\RequestException::create(Array, 500) #1 /var/www/fb/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 /var/www/fb/vendor/facebook/php-ads-sdk/src/FacebookAds/Api.php(152): FacebookAds\Http\Request->execute() #3 /var/www/fb/vendor/facebook/php-ads-sdk/src/FacebookAds/Api.php(194): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 /var/www/fb/vendor/facebook/php-ads-sdk/src/FacebookAds/Object/AbstractCrudObject.php(248): FacebookAds\Api->call('/act_1602736963...', 'POST', Array) #5 /var/www/fb/ads.php(46): FacebookAds\Object\AbstractCrudObject->create() #6 {main} thrown in /var/www/fb/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Exception/RequestException.php on line 137