cannot consume content type Rest API Response from Amazon Advertising API

475 Views Asked by At

I am hitting the /sb/negativeKeywords endpoint and every time I try to make a POST request, I get the following error:

StatusCodeError: 415 - {"code":"415","details":"Cannot consume content type"}

Notice that the documentation asks for a media type of application/vnd.sbnegativekeyword.v3.json.

We are able to hit other V3 endpoints with the same content type like "/sp/targets/keywords/recommendations" using the exact same headers except for "application/vnd.spkeywordsrecommendation.v3+json" as the "Content-Type". It seems that only the /sb/negativeKeywords route is giving us trouble.

Headers for request:

'Amazon-Advertising-API-ClientId': 'amzn1.application-oa2-client.xxxxxxx1',
'Content-Type': 'application/vnd.sbkeywordresponse.v3+json',
Authorization: 'Bearer Atza|IwEBIIPwm8y4K--xxxxxx-lPmAbVKr04Ms96butEfRXw1Lncix13NLSRO_Ww9ScjI_8gCvxxxxx-xxxxxx-xxxxxxx',
'Amazon-Advertising-API-Scope': 123123123123123123
}

Example body that throws error:

[
    {
       campaignId: 123123123, // valid campaign id
       adGroupId: 123123, // valid ad group id
       keywordText: 'Keyword 1',
       matchType: 'negativeExact'
    }
]

What are we doing wrong? We shouldn't be getting this error. We are using the content type that is suggested in the documentation. How would I know if this is an API problem and not a request problem? This is a widely used endpoint so it's very improbable that it's an API issue.

I'm using the following dependencies and node versions:

"request-promise": "4.2.6",
"ts-node": "10.7.0",
1

There are 1 best solutions below

0
mr_mooo_cow On

Just keep the content-type as 'application/json' and it will resolve the error.

Example:

headers = {
    'Authorization': f"Bearer {access_token}",
    'Amazon-Advertising-API-ClientId': str(client_id),
    'Amazon-Advertising-API-Scope': str(profile_id),
    'Content-Type': 'application/json'
}

endpoint = 'https://advertising-api.amazon.com'
interface = 'sb/negativeKeywords'
url = f"{endpoint}/{interface}"

payload = [{
    'campaignId': int(yourcampaignid),
    'adGroupId': int(youradgroupid),
    'keywordText': 'yourkeyword',
    'matchType': 'negativeExact'
}]

response = requests.post(url=url, headers=headers, json=payload)

Results in a [207] SUCCESS response.