Search code examples
pythonfacebookfacebook-graph-apifacebook-ads-apifacebook-python-business-sdk

Facebook APIs to retrieve deleted campaign insights


I'm using the python Facebook API's SDK. I am currently able to request and obtain campaign insights from the account level, with a snippet as such:

from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adsinsights import AdsInsights as Insights
account = AdAccount(u"act_{}".format(account_id))
report_params = {
    'time_increment': time_increment,
    'time_range': {
        'since': start_date.strftime("%Y-%m-%d"),
        'until': end_date.strftime("%Y-%m-%d"),
    },
    'level': 'campaign'
}
insights = account.get_insights(fields=['campaign_name', 'spend'],
                                params=report_params, pending=True).execute()

The problem is that I can't seem to get information about a deleted campaign, that was active for a time, meaning that it has a spend value.

Here I read that adding a filtering might give me also DELETED or ARCHIVED campaigns, but in the get_insights documentation page I can't seem to find a field to filter on, and every try has been unsuccessful


Solution

  • I found the right filter, even though the effective_status is not obtainable through insight fields, you can use it in filters, in my case I included every possible campaign.effective_status. Using the following report_params

    report_params = {
        'time_increment': time_increment,
        'time_range': {
            'since': start_date.strftime("%Y-%m-%d"),
            'until': end_date.strftime("%Y-%m-%d"),
        },
        'level': 'campaign',
        'filtering': [{'field': 'campaign.effective_status',
                       'operator': 'IN',
                       'value': ['ACTIVE', 'PAUSED', 'DELETED', 'PENDING_REVIEW', 'DISAPPROVED', 
                                 'PREAPPROVED', 'PENDING_BILLING_INFO', 'CAMPAIGN_PAUSED', 'ARCHIVED',
                                 'ADSET_PAUSED']}]
    }