I’m trying to get the daily spend per ad set for all our ad accounts. We’re spending lots of money with Facebook and Finance wants to see where it is going. Basically, I’m looking each day to get the spend per ad set for yesterday. The problem is, there are lots of ad sets.
I’m trying to do this in two parts. First get the ad set IDs from the Graph API. Then get the spend using the Marketing API.
1. Graph API (v.2.4)
I'm getting a list of all the ad sets we have. I cannot do this in one call, as there are to many results (over nine pages).
GET/v2.4/me/adaccounts?fields=name,adcampaign_groups{id,name,campaign_group_status,account_id,adcampaigns{id,name}}
2. Marketing API
To get the spend for yesterday, I'm making a call to the Marketing API for each ad set. This is the PHP code I’m using:
// Get spend for yesterday
$adSet = new \FacebookAds\Object\AdSet($adSetId);
$params = array(
'date_preset' => InsightsPresets::YESTERDAY,
);
/** @var Cursor $insights */
$insights = $adSet->getInsights(array('spend'), $params);
$insights->rewind();
$spend = 0;
if ($insights->current() != false) {
$spend = $insights->current()->getData()['spend'];
}
Since I have lots of ad sets, I’m hitting my trotting limit long before I get the data I need.
Is there any way to get this information in one call? If not, can I get the spend data from the Marketing API in less calls?
I’m happy to update to Graph API v2.5 if it helps. I’m using composer libraries:
facebook/php-sdk-v4: ~5.0
facebook/php-ads-sdk: 2.4.*
Thanks.