linkfox-amazon-ads-report

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Amazon Ads 报告获取

Amazon Ads Report Retrieval

报告一站式获取:脚本自动完成报告的创建、等待(约 2–10 分钟)、下载和解压,直接返回可读的结构化数据。 脚本本身不做"该选哪些列 / 该怎么分组"的业务判断,这些由 agent 先查
references/report-types/
下对应的
.md
文件,再显式传给脚本。
依赖
linkfox-amazon-ads-auth
(脚本启动自动检查;未安装时 exit 42,stderr 打
DEPENDENCY_MISSING
)。
One-stop report retrieval: The script automatically completes report creation, waiting (about 2–10 minutes), downloading, and decompression, and directly returns readable structured data. The script itself does not make business decisions such as "which columns to select / how to group"; these are first retrieved by the agent from the corresponding
.md
file under
references/report-types/
and then explicitly passed to the script.
Depends on
linkfox-amazon-ads-auth
(Automatically checked when the script starts; exits with code 42 and outputs
DEPENDENCY_MISSING
to stderr if not installed).

⚠️ 多账号场景:调用前必须解析好 profileId

⚠️ Multi-account scenario: Must resolve the profileId before calling

用户经常只说自然语言("美国站"、"日本站"、"我的店铺"),本 skill 的所有脚本都必须拿到数字
profileId
才能调。按下列顺序处理,不要跳过
  1. 先调
    linkfox-amazon-ads-auth
    authorized_stores.py
    拉出用户已授权的账号 × 站点清单。
  2. 根据用户提到的站点(映射到
    countryCode
    ,如 美国→
    US
    )匹配候选 profile:
    • 只有 1 个候选 → 静默取对应 profileId,继续调用;不要把 profileId 数字播报给用户。
    • ≥ 2 个候选(同站点下多个授权账号)必须向用户澄清,用
      accountName
      问:"你在美国站授权了 A 和 B 两个账号,这次用哪个?"
    • 0 个候选 → 告知用户该站点未授权,引导去
      linkfox-amazon-ads-auth
      做授权。
  3. 严禁让用户直接报 profileId 数字。
  4. 严禁在歧义下"挑第一个"或"选默认"绕过澄清。
完整决策表见
linkfox-amazon-ads-auth
SKILL.md 的 Usage Scenarios 第 4 节
Users often use natural language (e.g., "US site", "Japan site", "my store"), and all scripts of this skill must obtain the numeric
profileId
to execute. Follow the steps below in order, do not skip any:
  1. First call
    authorized_stores.py
    of
    linkfox-amazon-ads-auth
    to pull the list of user-authorized accounts × sites.
  2. Match candidate profiles based on the site mentioned by the user (mapped to
    countryCode
    , e.g., US→
    US
    ):
    • Only 1 candidate → Silently take the corresponding profileId and proceed with the call; do not announce the profileId number to the user.
    • ≥ 2 candidates (multiple authorized accounts under the same site)Must clarify with the user, using
      accountName
      to ask: "You have authorized accounts A and B for the US site, which one would you like to use this time?"
    • 0 candidates → Inform the user that the site is not authorized, and guide them to complete authorization via
      linkfox-amazon-ads-auth
      .
  3. Strictly prohibit asking users to directly provide the profileId number.
  4. Strictly prohibit bypassing clarification by "picking the first one" or "selecting default" when there is ambiguity.
The complete decision table can be found in Section 4 of Usage Scenarios in SKILL.md of
linkfox-amazon-ads-auth
.

Core Concepts

Core Concepts

  • 覆盖:SP / SB 全部报告类型(以
    references/report-types/
    下存在的
    .md
    为准;SD / ST / DSP 暂未覆盖)
  • 一站式:脚本内部自动完成报告创建 → 等待生成(约 2–10 分钟)→ 下载 → 解压,调用方只需等最终结果
  • 单脚本
    get_report.py
    (覆盖 SP / SB 全部 adProduct)
  • 元数据 vs. 运行参数
    • 每个报告类型的可用字段(timeUnit / groupBy / filters / 全部列名)集中在
      references/report-types/<adProduct-dir>/<reportTypeId>.md
    • 脚本运行参数(等待间隔、访问链接时效等)见本文件和
      references/api.md
  • Coverage: All report types of SP / SB (based on the
    .md
    files under
    references/report-types/
    ; SD / ST / DSP are not covered yet)
  • One-stop: The script internally and automatically completes report creation → waiting for generation (about 2–10 minutes) → downloading → decompression; the caller only needs to wait for the final result
  • Single script:
    get_report.py
    (covers all adProducts of SP / SB)
  • Metadata vs. Runtime Parameters:
    • Available fields (timeUnit / groupBy / filters / all column names) for each report type are centralized in
      references/report-types/<adProduct-dir>/<reportTypeId>.md
    • Script runtime parameters (polling interval, access link validity, etc.) can be found in this document and
      references/api.md

可用脚本

Available Scripts

脚本职责
get_report.py
一站式执行。必填
adProduct
/
groupBy
/
columns
,由 agent 从 report-types/ 提取后传入
check_auth_dependency.py
检测 linkfox-amazon-ads-auth 是否安装
完整脚本参数、响应结构见
references/api.md
ScriptResponsibility
get_report.py
One-stop execution. Required parameters
adProduct
/
groupBy
/
columns
must be extracted by the agent from report-types/ and passed in
check_auth_dependency.py
Checks if linkfox-amazon-ads-auth is installed
Complete script parameters and response structure can be found in
references/api.md
.

Agent 调用流程

Agent Calling Flow

Agent 触达"拉取亚马逊广告报告"类需求时,必须按下列顺序:
  1. 定 reportTypeId:按用户意图挑选(如"上周花费"→
    spCampaigns
    ;"哪个商品卖得好"→
    spAdvertisedProduct
    /
    sbPurchasedProduct
    ;"用户搜什么词找到我"→
    spSearchTerm
  2. 查 reference:打开
    references/report-types/<adProduct-dir>/<reportTypeId>.md
    • frontmatter 给出:
      adProduct
      /
      groupBy
      (Configuration 表推荐的) /
      timeUnit
      (可枚举) /
      format
      /
      dateRange
      /
      filters
    • Base metrics 表 给出:此报告类型允许的全部列名
  3. 向用户咨询可定制条件(用户答"默认/随便"时跳过,进入第 4 步的默认选择):
    • timeUnit
      :DAILY(按日拆分)还是 SUMMARY(汇总)
    • columns
      扩展:是否要归因列(sales7d / purchases7d / acosClicks7d / roasClicks7d)、视频指标、newToBrand 等
    • filters
      :是否过滤 campaignStatus / keywordType / adStatus 等
  4. 按用户回复或默认构造 columns(见下节 "默认条件")
  5. 调脚本
    adProduct
    /
    groupBy
    /
    columns
    三个必填字段显式传入
When the Agent receives a request like "pull Amazon Ads reports", must follow the steps below in order:
  1. Determine reportTypeId: Select based on user intent (e.g., "last week's spend"→
    spCampaigns
    ; "which products sold well"→
    spAdvertisedProduct
    /
    sbPurchasedProduct
    ; "what terms did users search to find me"→
    spSearchTerm
    )
  2. Check reference: Open
    references/report-types/<adProduct-dir>/<reportTypeId>.md
    • frontmatter provides:
      adProduct
      /
      groupBy
      (recommended in Configuration table) /
      timeUnit
      (enumerable) /
      format
      /
      dateRange
      /
      filters
    • Base metrics table provides: all column names allowed for this report type
  3. Consult user for customizable conditions (skip if user replies "default/whatever" and proceed to default selection in Step 4):
    • timeUnit
      : DAILY (split by day) or SUMMARY (aggregated)
    • columns
      extension: Whether to add attribution columns (sales7d / purchases7d / acosClicks7d / roasClicks7d), video metrics, newToBrand, etc.
    • filters
      : Whether to filter campaignStatus / keywordType / adStatus, etc.
  4. Construct columns based on user reply or default conditions (see "Default Conditions" section below)
  5. Call the script: Explicitly pass in the three required fields
    adProduct
    /
    groupBy
    /
    columns

默认条件(用户未指定时使用)

Default Conditions (Used when user does not specify)

条件默认规则
timeUnit
日期跨度 ≤ 7 天 →
DAILY
;> 7 天 →
SUMMARY
columns
身份维度
DAILY
时必含
date
SUMMARY
时必含
startDate
+
endDate
;再追加该报告的主键字段(参考 frontmatter 中 groupBy 对应的主键,如 campaignId+campaignName / advertisedAsin+advertisedSku / searchTerm / keyword 等)
columns
基础指标
impressions
/
clicks
/
cost
(以该报告 Base metrics 存在的为准)
columns
归因指标
仅当用户提到"销售/转化/ROI/ACOS"等意图时追加
sales7d
/
purchases7d
/
acosClicks7d
/
roasClicks7d
(以 Base metrics 存在者为准)
filters
不加(全量返回)
groupBy
取 frontmatter
groupBy
数组的第一个值(即 Configuration 表里 Amazon 官方推荐的主维度)
ConditionDefault Rule
timeUnit
Date range ≤ 7 days →
DAILY
; > 7 days →
SUMMARY
columns
Identity Dimension
Must include
date
for
DAILY
; must include
startDate
+
endDate
for
SUMMARY
; then add the primary key fields of the report (refer to the primary key corresponding to groupBy in frontmatter, such as campaignId+campaignName / advertisedAsin+advertisedSku / searchTerm / keyword, etc.)
columns
Basic Metrics
impressions
/
clicks
/
cost
(based on what exists in the report's Base metrics)
columns
Attribution Metrics
Only add when user mentions intent like "sales/conversion/ROI/ACOS":
sales7d
/
purchases7d
/
acosClicks7d
/
roasClicks7d
(based on what exists in Base metrics)
filters
No filters applied (return full data)
groupBy
Take the first value in the frontmatter
groupBy
array (i.e., the primary dimension recommended by Amazon in the Configuration table)

请求示例

Request Examples

所有 example 都显式传入三个必填字段(
adProduct
/
groupBy
/
columns
)。
All examples explicitly pass in the three required fields (
adProduct
/
groupBy
/
columns
).

1. SP 广告活动报告(最常见)

1. SP Campaign Report (Most Common)

bash
python scripts/get_report.py '{
  "profileId": 1234567890, "region": "NA",
  "reportTypeId": "spCampaigns",
  "adProduct": "SPONSORED_PRODUCTS",
  "groupBy": ["campaign"],
  "columns": ["date","campaignId","campaignName","impressions","clicks","cost"],
  "startDate": "2026-04-27","endDate": "2026-05-03",
  "timeUnit": "DAILY"
}'
bash
python scripts/get_report.py '{
  "profileId": 1234567890, "region": "NA",
  "reportTypeId": "spCampaigns",
  "adProduct": "SPONSORED_PRODUCTS",
  "groupBy": ["campaign"],
  "columns": ["date","campaignId","campaignName","impressions","clicks","cost"],
  "startDate": "2026-04-27","endDate": "2026-05-03",
  "timeUnit": "DAILY"
}'

2. SP 搜索词报告(含归因)

2. SP Search Term Report (with Attribution)

bash
python scripts/get_report.py '{
  "profileId": 1234567890, "region": "NA",
  "reportTypeId": "spSearchTerm",
  "adProduct": "SPONSORED_PRODUCTS",
  "groupBy": ["searchTerm"],
  "columns": ["searchTerm","keyword","matchType","impressions","clicks","cost",
              "sales7d","sales14d","purchases7d","acosClicks14d","roasClicks14d",
              "startDate","endDate"],
  "startDate": "2026-04-01","endDate": "2026-04-30",
  "timeUnit": "SUMMARY",
  "filters": [{"field":"keywordType","values":["BROAD","PHRASE","EXACT"]}]
}'
bash
python scripts/get_report.py '{
  "profileId": 1234567890, "region": "NA",
  "reportTypeId": "spSearchTerm",
  "adProduct": "SPONSORED_PRODUCTS",
  "groupBy": ["searchTerm"],
  "columns": ["searchTerm","keyword","matchType","impressions","clicks","cost",
              "sales7d","sales14d","purchases7d","acosClicks14d","roasClicks14d",
              "startDate","endDate"],
  "startDate": "2026-04-01","endDate": "2026-04-30",
  "timeUnit": "SUMMARY",
  "filters": [{"field":"keywordType","values":["BROAD","PHRASE","EXACT"]}]
}'

3. SB 广告组报告

3. SB Ad Group Report

bash
python scripts/get_report.py '{
  "profileId": 1234567890, "region": "NA",
  "reportTypeId": "sbAdGroup",
  "adProduct": "SPONSORED_BRANDS",
  "groupBy": ["adGroup"],
  "columns": ["adGroupId","adGroupName","impressions","clicks","cost","purchases","sales","startDate","endDate"],
  "startDate": "2026-04-01","endDate": "2026-04-30"
}'
bash
python scripts/get_report.py '{
  "profileId": 1234567890, "region": "NA",
  "reportTypeId": "sbAdGroup",
  "adProduct": "SPONSORED_BRANDS",
  "groupBy": ["adGroup"],
  "columns": ["adGroupId","adGroupName","impressions","clicks","cost","purchases","sales","startDate","endDate"],
  "startDate": "2026-04-01","endDate": "2026-04-30"
}'

4. 轮询一个已有 reportId(救回上次超时 / 手工恢复)

4. Poll an Existing reportId (Recover from previous timeout / manual recovery)

当上次运行因为客户端轮询窗口太短退出、但报告在 Amazon 侧仍在跑时,直接传入
reportId
即可跳过创建,继续轮询并下载。此模式下只需
profileId
/
region
/
reportId
,其余字段不必填。
bash
python scripts/get_report.py '{
  "profileId": 1234567890, "region": "NA",
  "reportId": "7df1ef5d-45ba-40cc-b607-ff2148cf4f5e",
  "maxAttempts": 60, "pollInterval": 30
}'
自动恢复:如果调用方未传
reportId
、且 Amazon 对同参数请求触发去重(返回 HTTP 425
The Request is a duplicate of : <uuid>
),脚本会自动解析出老 reportId 并转为轮询该老报告,无需重试。
When the last run exited due to a too-short client polling window but the report is still being generated on Amazon's side, directly pass in
reportId
to skip creation and continue polling and downloading. In this mode, only
profileId
/
region
/
reportId
are required; other fields are optional.
bash
python scripts/get_report.py '{
  "profileId": 1234567890, "region": "NA",
  "reportId": "7df1ef5d-45ba-40cc-b607-ff2148cf4f5e",
  "maxAttempts": 60, "pollInterval": 30
}'
Auto-recovery: If the caller does not pass
reportId
and Amazon triggers deduplication for the same parameter request (returns HTTP 425
The Request is a duplicate of : <uuid>
), the script will automatically parse the old reportId and switch to polling that old report, no retry is needed.

响应格式

Response Format

成功:
json
{
  "success": true,
  "reportId": "4ee811a0-...",
  "reportTypeId": "spCampaigns",
  "startDate": "2026-04-28", "endDate": "2026-05-04",
  "downloadPath": "C:/.../tmp/report_data.json",
  "extractedFileHttpUrl": "http://127.0.0.1:51234/download",
  "extractedFileHttpServeSeconds": 300
}
失败:
json
{"error":"Upstream HTTP 400","httpStatus":400,
 "body":"{\"code\":\"400\",\"detail\":\"startDate to endDate range (32 days) must not exceed maximum range (31 days)\"}"}
Success:
json
{
  "success": true,
  "reportId": "4ee811a0-...",
  "reportTypeId": "spCampaigns",
  "startDate": "2026-04-28", "endDate": "2026-05-04",
  "downloadPath": "C:/.../tmp/report_data.json",
  "extractedFileHttpUrl": "http://127.0.0.1:51234/download",
  "extractedFileHttpServeSeconds": 300
}
Failure:
json
{"error":"Upstream HTTP 400","httpStatus":400,
 "body":"{\"code\":\"400\",\"detail\":\"startDate to endDate range (32 days) must not exceed maximum range (31 days)\"}"}

调用原则

Calling Principles

  • 用户指定了 reportTypeId 就只拉那一种,不擅自替换
  • 报告失败(非 2xx 或 status=FAILED)时如实告知错误原因,不盲目重试
  • 成功后把报告的本地文件路径和访问链接完整展示给用户,并提醒访问链接有时效(默认 5 分钟内有效,过期需重新拉取)
  • 超时不是失败:当脚本返回
    status=STILL_PROCESSING
    (exit code=2),说明客户端已等满默认 10 分钟但报告仍在 Amazon 侧生成。此时 必须向用户说明情况并询问是否继续等待,绝不能当成失败处理。参考回复:"报告还在 Amazon 侧生成中(已等 10 分钟),要继续等吗?可以选:A. 再等 ~20 分钟(maxAttempts=60)、B. 再等 ~1 小时(maxAttempts=120)、C. 先停,我稍后用 reportId 回来。" 用户选 A/B → 用
    resumeHint.params
    切到仅轮询模式续跑
  • Only pull the specified reportTypeId if the user has specified it; do not replace it without permission
  • When report generation fails (non-2xx or status=FAILED), truthfully inform the user of the error reason; do not retry blindly
  • After success, fully display the local file path and access link of the report to the user, and remind them that the access link has a validity period (valid for 5 minutes by default, need to pull again if expired)
  • Timeout is not failure: When the script returns
    status=STILL_PROCESSING
    (exit code=2), it means the client has waited the default 10 minutes but the report is still being generated on Amazon's side. At this time, must explain the situation to the user and ask if they want to continue waiting; never treat it as a failure. Reference reply: "The report is still being generated on Amazon's side (waited 10 minutes), do you want to continue waiting? You can choose: A. Wait another ~20 minutes (maxAttempts=60), B. Wait another ~1 hour (maxAttempts=120), C. Stop now, I'll come back with the reportId later." If the user selects A/B → use
    resumeHint.params
    to switch to polling-only mode and continue running

常见错误

Common Errors

状态含义建议
Missing required parameters: adProduct/groupBy/columns
调用方未显式传入三必填回到 "Agent 调用流程" 第 2 步,从
references/report-types/<adProduct-dir>/<reportTypeId>.md
读出并补上
HTTP 401
accessToken 过期调 ads-auth 的
refresh_token.py
后重试
HTTP 403
未关联广告账户或权限不足到 Amazon Ads 后台检查经理账户/广告账户关联
HTTP 400 "must not exceed maximum range"
日期跨度超限(多数 31 天)拆分拉取后本地合并;具体上限看对应
.md
frontmatter
dateRange.maxSpanDays
HTTP 400
columns
/
groupBy
校验错
列名拼写错 / 与 reportTypeId 不匹配 / 超出 Base metrics对照
.md
文件 Base metrics 表核对
status=FAILED
failureReason
上游生成失败多为日期窗口或权限问题,按 failureReason 具体处理
status=STILL_PROCESSING
(exit 2)
客户端轮询窗口耗尽但报告仍在生成不是失败。stdout 已含
reportId
resumeHint.params
。询问用户是否继续等,用该 params(带
reportId
+ 更大
maxAttempts
)切到仅轮询模式续跑
HTTP 425 "duplicate of"
同参数已有在跑的报告脚本自动解析并转为轮询该老 reportId,正常情况下调用方无需干预
exit 42依赖 skill 未安装先装
linkfox-amazon-ads-auth
StatusMeaningSuggestion
Missing required parameters: adProduct/groupBy/columns
Caller did not explicitly pass in the three required parametersGo back to Step 2 of "Agent Calling Flow", read and supplement the parameters from
references/report-types/<adProduct-dir>/<reportTypeId>.md
HTTP 401
accessToken expiredCall
refresh_token.py
of ads-auth and retry
HTTP 403
No associated ad account or insufficient permissionsCheck the manager account/ad account association in the Amazon Ads backend
HTTP 400 "must not exceed maximum range"
Date range exceeds limit (most are 31 days)Split the pull and merge locally; refer to the frontmatter
dateRange.maxSpanDays
of the corresponding
.md
file for the specific limit
HTTP 400
with
columns
/
groupBy
validation error
Column name misspelled / does not match reportTypeId / exceeds Base metricsCheck against the Base metrics table in the
.md
file
status=FAILED
with
failureReason
Upstream generation failedMostly due to date window or permission issues; handle according to the specific failureReason
status=STILL_PROCESSING
(exit 2)
Client polling window exhausted but report is still being generatedNot a failure. stdout already contains
reportId
and
resumeHint.params
. Ask the user if they want to continue waiting, and use the params (with
reportId
+ larger
maxAttempts
) to switch to polling-only mode and continue running
HTTP 425 "duplicate of"
A report with the same parameters is already runningThe script will automatically parse and switch to polling the old reportId; no intervention is needed from the caller under normal circumstances
exit 42Dependent skill not installedInstall
linkfox-amazon-ads-auth
first

日期与数据

Dates and Data

  • 日期跨度上限:多数报告 31 天;
    sbPurchasedProduct
    是 731 天;
    spGrossAndInvalids
    /
    sbGrossAndInvalids
    /
    sdGrossAndInvalids
    是 365 天(以 frontmatter 为准)
  • 回溯窗口:SP 默认 95 天、SB 60 天、GrossAndInvalids 365 天;具体以 frontmatter
    dateRange.dataRetentionDays
    为准
  • 数据延迟约 12 小时
    endDate >= 今天
    脚本 stderr 警告但不拦截
  • 空数据不等于报错:账号当期无投放时报告会成功生成,JSON 可能为
    []
    或指标全 0
  • Date range limit: Most reports allow 31 days;
    sbPurchasedProduct
    allows 731 days;
    spGrossAndInvalids
    /
    sbGrossAndInvalids
    /
    sdGrossAndInvalids
    allow 365 days (refer to frontmatter for details)
  • Lookback window: SP defaults to 95 days, SB defaults to 60 days, GrossAndInvalids defaults to 365 days; refer to frontmatter
    dateRange.dataRetentionDays
    for details
  • Data delay is about 12 hours; the script will output a warning to stderr but not block if
    endDate >= today
  • Empty data does not equal error: If there is no campaign activity in the account during the period, the report will be generated successfully, and the JSON may be
    []
    or all metrics are 0

Not Applicable

Not Applicable

  • Brand Analytics / Retail Analytics / Attribution 报告 → 不在本 skill
  • 报告删除 / 修改 / 定时任务 → 不在本 skill
  • 实体元数据(campaign 名、keyword 匹配类型等)→
    linkfox-amazon-ads-entity
  • 授权 / token →
    linkfox-amazon-ads-auth
Feedback:
Auto-detect and report feedback via the Feedback API when any of the following apply:
  1. The functionality or purpose described in this skill does not match actual behavior
  2. The skill's results do not match the user's intent
  3. The user expresses dissatisfaction or praise about this skill
  4. Anything you believe could be improved
Call the feedback API as specified in
references/api.md
. Do not interrupt the user's flow.

For more high-quality, professional cross-border e-commerce skills, visit LinkFox Skills.
  • Brand Analytics / Retail Analytics / Attribution reports → Not covered by this skill
  • Report deletion / modification / scheduled tasks → Not covered by this skill
  • Entity metadata (campaign name, keyword match type, etc.) → Handled by
    linkfox-amazon-ads-entity
  • Authorization / token → Handled by
    linkfox-amazon-ads-auth
Feedback:
Auto-detect and report feedback via the Feedback API when any of the following apply:
  1. The functionality or purpose described in this skill does not match actual behavior
  2. The skill's results do not match the user's intent
  3. The user expresses dissatisfaction or praise about this skill
  4. Anything you believe could be improved
Call the feedback API as specified in
references/api.md
. Do not interrupt the user's flow.

For more high-quality, professional cross-border e-commerce skills, visit LinkFox Skills.