Apple Search Ads API - Multiple Countries/Regions

I'm generating reports for a few campaigns with the Search Ads API. I've been running into this problem, where if a campaign is running in multiple countries (in my specific case: ['AR', 'CL', 'CO', 'PE']), I'm unable to find a way to get more granular results. The report only shows that list in the metadata.

So my question is: is there any way to determine how well the ad performs in each country in the list as opposed to seeing the results grouped together?

json payload:

json = {
    "startTime": start_date,
    "endTime": end_date,
    "selector": {
        "orderBy": [
            {
                "field": sort_field,
                "sortOrder": sort_order
            }
        ],
        "conditions": conditions,
        "pagination": {
            "offset": offset,
            "limit": limit
        }
    },
    "timeZone": "UTC",
    "returnRecordsWithNoMetrics": no_metrics,
    "returnRowTotals": return_row_totals,
    "granularity":granularity,
    "returnGrandTotals": return_grand_totals
}

post request:

requests.post("https://api.searchads.apple.com/api/v4/reports/campaigns", json=json, headers=headers)

campaign metadata:

{'campaignId': CAMPAIGN_ID,
 'campaignName': CAMPAIGN_NAME,
 'deleted': False,
 'campaignStatus': 'PAUSED',
 'app': {'appName': APP_NAME, 'adamId': ADAMID},
 'servingStatus': 'NOT_RUNNING',
 'servingStateReasons': ['PAUSED_BY_USER'],
 'countriesOrRegions': ['AR', 'CL', 'CO', 'PE'],
 'modificationTime': '2021-12-14T23:42:57.281',
 'totalBudget': {'amount': AMOUNT, 'currency': 'USD'},
 'dailyBudget': {'amount': AMOUNT, 'currency': 'USD'},
 'displayStatus': 'PAUSED',
 'supplySources': ['APPSTORE_SEARCH_RESULTS'],
 'adChannelType': 'SEARCH',
 'orgId': ORG_ID,
 'countryOrRegionServingStateReasons': {},
 'billingEvent': 'TAPS'}

As you can see, there's a list of countries. At the moment, I am unaware of how to break it down into specific countries.

Replies

Hey Joe,

Looks like you don't have a "countryOrRegion" indicated in a groupBy field in your request. I believe if you add a groupBy field with "countryOrRegion" listed then the results should aggregate down to the country. They have it all of the groupBy fields listed on their official documentation here. They also have it in their sample payload here and that I modeled my calls after and its working for me. The documentation states that "If groupBy specifies age, gender, and geodimensions, returnRowTotals and returnGrandTotals must be false" but this is inconsistent with their sample payload.

Hope this helps!

json = {
    "startTime": start_date,
    "endTime": end_date,
    "selector": {
        "orderBy": [
            {
                "field": sort_field,
                "sortOrder": sort_order
            }
        ],
        "conditions": conditions,
        "pagination": {
            "offset": offset,
            "limit": limit
        }
    },
    "groupBy": [ 
       "countryOrRegion"
     ],
    "timeZone": "UTC",
    "returnRecordsWithNoMetrics": no_metrics,
    "returnRowTotals": return_row_totals,
    "granularity": granularity,
    "returnGrandTotals": return_grand_totals