主页文档代码示例API 参考公告模型发行说明常见问题GitHub视频
开发者中心API 状态支持
文档
开发者中心API 状态支持

使用 Postman 创建销售伙伴 API 模型

使用 Postman 创建销售伙伴 API 模型

本文档介绍如何为销售伙伴 API (SP-API) 模型设置和使用 {{0}}。您可以使用 {{1}} 生成使用亚马逊账户登录 (LWA) 访问令牌、调用 SP-API 端点以及调用 SP-API 沙箱端点。

进行调用所需的凭证

使用 Postman 生成 “用亚马逊账户登录” (LWA) 访问令牌

使用亚马逊账户登录 (LWA) 允许亚马逊买家使用其亚马逊用户名和密码登录已注册的第三方网站或移动应用程序(“客户端”)。客户端可能会要求买家共享其亚马逊个人资料中的一些个人信息,包括姓名、电子邮件地址和邮政编码。在 SP-API 模型中使用 {{0}} 之前,您必须先生成访问令牌才能向 SP-API 进行身份验证。

  1. 打开 邮差 并登录您的账户。

  2. 对于 Workspaces,选择您的工作空间。

  3. 选择 New

  4. Create New 对话框,选择 HTTP Request

    The Create New Window, which shows the HTTP Request as the first item to choose from.

  5. 对于 Request,选择 POST

    The Request dropdown menu with POST selected.

  6. 将以下链接复制并粘贴到文本框中。

    https://api.amazon.com/auth/o2/token

    the link pasted into the request field.

  7. 选择 Authorization 选项卡和 for Type,选择 No Auth

    The Type dropdown menu with No Auth selected.

  8. 选择 Body 选项卡,然后选择 x-www-form-urlencoded

    The Body tab selected and x-www-form-urlencoded selected.

  9. Body 表,添加以下键值对:

    Value
    grant_typerefresh_token
    refresh_token[您的刷新令牌值]
    client_id[您的客户端 ID 值]
    client_secret[您的客户端密钥值]

    The key-value pairs from the table entered into the table on the Body tab.

  10. 选择 Send

响应返回您用于向 SP-API 进行身份验证的访问令牌。

"access_token": "Atza|*****", "refresh_token": "Atzr|*****"' "token_type": "bearer", "expires_in": 3600

将 SP-API 模型导入 Postman

在调用 SP-API 端点之前,必须将 SP-API 模型导入 {{0}}。

  1. 打开 GitHub 上的 selling-partner-api-models 文件夹。

  2. 在文件夹列表中,找到并选择要下载的 API 模型,然后选择 JSON 文件。

  3. 在 JSON 文件视图上,选择 Raw 查看源代码或选择下载图标以下载原始文件。

  4. 复制模型源代码。

  5. 打开文本编辑器(如记事本)并粘贴模型文本。然后,以“.json”扩展名保存文件。

  6. 登录 Postman。

  7. 对于 Workspaces,选择您的工作空间。

  8. 选择 Import,选择你的 JSON 文件,然后选择 Open

  9. Import 对话框,选择 Postman Collection 然后选择 Import

    The Choose how to import your API pop-up page. The Postman Collection option is chosen and has a red box surrounding it. The Import button on the bottom right of the page is also surrounded by a red box.

成功导入后,将显示一条成功消息。

A success message stating that 1 out of 1 element was imported and the name of the collection Selling Partner API for Sellers.

调用 SP-API 端点

  1. 登录 Postman。

  2. 对于 Workspaces,选择您的工作空间。

  3. Collections 选项卡,选择新导入的 API 并选择 GET 操作。

  4. 如果还没有 LWA 访问令牌,请使用 Postman 生成 LWA 访问令牌。您需要 LWA 访问令牌才能生成刷新令牌。

  5. Headers 选项卡,添加以下密钥对:

    Value
    x-amz-access-token[您的访问令牌值]

    The On the Headers tab, when the x-amz-access-token Key is highlighted and the Value is entered with sample text.

  6. 选择 Send

响应文本填充在 Response 窗口。

调用 SP-API 沙箱端点

调用销售伙伴 API 沙箱的过程与进行生产调用的过程相同,不同之处在于您要将调用指向销售伙伴 API 沙箱端点。销售伙伴 API 提供了两个沙箱环境,可供您在不影响生产数据、不触发真实事件的前提下测试应用程序。

销售伙伴 API 静态沙箱使用模式匹配来返回静态的模拟响应。销售伙伴 API 动态沙箱将请求路由到沙箱后端,后端可以根据请求参数返回真实的响应。

请参阅销售伙伴 API 沙箱,了解详细信息。

  1. 登录 Postman。

  2. 将您正在使用的 API 的 Swagger 模型导入到您的 https://github.com/amzn/selling-partner-api-models/blob/main/models/orders-api-model/ordersV0.json 工作区。例如,订单 API Swagger 模型

  3. 对于 Workspaces,选择您的工作空间。

  4. Collections 选项卡,选择您的收藏并选择 GET 操作。例如,如果您想测试 GET Orders API 调用,请选择 get Orders API 调用。

  5. {{baseUrl}} 设置为销售伙伴 API 沙箱

  6. Params 选项卡上,传递来自 Swagger 模型的静态请求值。例如,订单 API

    The Params tab, which has the CreatedAfter and Markdetplaceids Keys.

  7. 调用沙箱端点时,您需要检查您的请求是否包含相应 Swagger 模型中定义的所有必需参数。请参考以下订单 API v0 Swagger 模型示例,其中 Get Order API 调用突出显示为成功响应:

    The Get Order API call, which has a successful response.

  8. 如果还没有 LWA 访问令牌,请使用 Postman 生成 LWA 访问令牌。您需要 LWA 访问令牌才能交换刷新令牌。

  9. Headers 选项卡,添加以下密钥对:

    Value
    x-amz-access-token[您的访问令牌值]

    The On the Headers tab, when the x-amz-access-token Key is highlighted and the Value is entered with sample text.

  10. 选择 Send

  11. 验证响应返回的有效负荷是否与 Swagger 模型相匹配。

    响应文本填充在 Response 窗口。

    The Sandbox response example, which shows the returned order information.


此页面对您有帮助吗?