AWS Ads无法创建SponsoredBrands报告:reportTypeId无效报错
解决Amazon Ads API请求Sponsored Brands报告时的reportTypeId无效错误
问题分析
请求返回400错误,提示configuration reportTypeId is unknown or invalid,核心问题有两个:
- Content-Type头部格式错误,多了一个斜杠,导致服务器无法正确解析请求体
- 使用了旧版API的reportTypeId标识,v3 API采用了全新的报告类型ID
修正步骤
1. 修复Content-Type头部
将headers中的Content-Type值从application//vnd.createasyncreportrequest.v3+json改为application/vnd.createasyncreportrequest.v3+json(移除多余的斜杠)。
2. 替换正确的reportTypeId
v3 API中,"按广告活动分组的Sponsored Brands广告活动摘要报告"对应的正确reportTypeId是SPONSORED_BRANDS_CAMPAIGN_SUMMARY,而非旧版的sbCampaigns。
修正后的代码
REPORT_ENDPOINT = "https://advertising-api.amazon.com/reporting/reports" headers = { "Authorization": f"Bearer {access_token}", "Amazon-Advertising-API-ClientId": self.credentials["client_id"], "Amazon-Advertising-API-Scope": self.credentials["profile_id"], "Content-Type": "application/vnd.createasyncreportrequest.v3+json" # 修复斜杠问题 } report_request = { "name": "SponsoredBrandsReport", "startDate": self.startdate, "endDate": self.enddate, "configuration": { "adProduct": "SPONSORED_BRANDS", "groupBy": [ "campaign" ], "columns": [ "campaignName", "impressions", "clicks", "cost", "sales", "purchases", "unitsSold" ], "reportTypeId": "SPONSORED_BRANDS_CAMPAIGN_SUMMARY", # 使用v3正确的报告类型ID "timeUnit": "SUMMARY", "format": "GZIP_JSON" } }
额外验证点
- 确认
startDate和endDate格式为YYYY-MM-DD,符合API要求 - 检查
access_token、client_id、profile_id的有效性及权限范围
内容的提问来源于stack exchange,提问作者Zeke
相关产品推荐
相关产品推荐

