Search code examples
apicurlapple-search-ads

Apple Search Ads returning error while "groupBy" clause


I have setup a tool to query the Apple Search Ads API, the documentation for which can be found here. One can pass a "groupBy" clause to the request, like so:

curl -X POST https://api.searchads.apple.com/api/v1/reports/campaigns  \
-H 'Content-Type: application/json'  \
-H 'Authorization: orgId=1056160'  \
-E pem.pem --key key.key \
-d '{"selector": {"pagination": {"limit": 10, "offset": 0}, "orderBy": [{"sortOrder": "DESCENDING", "field": "campaignId"}]}, "returnRecordsWithNoMetrics": false, "granularity": "DAILY", "returnRowTotals": false, "timeZone": "UTC", "endTime": "2019-03-27", "startTime": "2019-02-27", "groupBy": "countryCode"}' \
| python -m json.tool

and expect back data grouped by countryCode.

However, since 23 April, 2019, the API began to return an error:

{
    "data": null,
    "error": {
        "errors": [
            {
                "field": "Line#:1 Column#:292",
                "message": "This is an invalid request. At least one field format is not readable by the system.",
                "messageCode": "INVALID_ATTRIBUTE_TYPE"
            }
        ]
    },
    "pagination": null
}

I tried looking for help online but have come short so far. Any help will be greatly appreciated.


Solution

  • What reporting endpoint are you hitting?

    reports/campaigns?

    If it's campaigns endpoint, try this payload:

    {
        "startTime": "2019-02-27",
        "endTime": "2019-03-27",
        "granularity": "DAILY",
        "selector": {
            "orderBy": [
                {
                    "field": "campaignId",
                    "sortOrder": "DESCENDING"
                }
            ],
            "conditions": [
            ],
            "pagination": {
                "offset": 0,
                "limit": 10
            }
        },
         "groupBy": [
            "countryCode"
        ],
        "timeZone": "UTC",
        "returnRecordsWithNoMetrics": false,
        "returnRowTotals": false,
        "returnGrandTotals": false
    }