You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Amazon Advertising API请求绩效报告时遇「无法处理内容类型」错误

Fixing "Cannot consume content type" Error with Amazon Advertising API Campaign Report Request

Hey there! I ran into this exact same error a few months back when working with the Amazon Advertising API, so I can help you troubleshoot this.

The "Cannot consume content type" error almost always points to a mismatch between what your request is sending and what the API expects for the application/json content type. Let's break down the most likely issues and fixes:

1. Fix JSON Syntax in Your Request Body

Looking at your request body snippet: { campaignType:'sponsoredProducts',...} — this is the biggest red flag. JSON requires double quotes for all keys and string values, not single quotes. The API's JSON parser will reject any payload using single quotes outright.

Correct Example Request Body

{
  "campaignType": "sponsoredProducts",
  "reportDate": "2024-05-20",
  "metrics": ["impressions", "clicks", "cost"],
  "groupBy": ["campaign"]
}

Make sure to:

  • Replace all single quotes (') with double quotes (")
  • Remove any trailing commas at the end of object/array items (e.g., don't leave a comma after the last metric in the array)
  • Ensure all nested brackets/parentheses are properly closed

2. Ensure You're Sending a Proper JSON String

Even if your object looks correct, if you're sending a raw language object (like a JavaScript object or Python dict) instead of a serialized JSON string, the API won't parse it correctly.

For example, in JavaScript/Node.js:

// Wrong: Sending the object directly
axios.post('https://advertising-api.amazon.com/v1/campaigns/report', { campaignType: 'sponsoredProducts' }, { headers })

// Correct: Serialize to JSON string
axios.post('https://advertising-api.amazon.com/v1/campaigns/report', JSON.stringify({ campaignType: 'sponsoredProducts' }), { headers })

If you're using tools like Postman or Insomnia, double-check that you've selected the raw body type with JSON (not Text or Form Data) from the dropdown.

3. Verify Request Header Accuracy

While your headers look correct at a glance, double-check:

  • No typos in Content-Type: application/json (e.g., missing hyphens, extra spaces)
  • Ensure the Amazon-Advertising-API-Scope ID matches the correct marketplace/account you're targeting (though this usually throws a different error, it's worth confirming)

Quick Test to Validate

If you're unsure about your payload, paste it into a JSON validator tool (like the built-in one in Chrome DevTools) to catch syntax errors before sending it to the API.

Once you fix the JSON syntax and ensure you're sending a proper serialized string, the "Cannot consume content type" error should disappear.

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:20:40