设置Amazon SP-API通知API

发布于 2025-01-22 03:05:12 字数 154 浏览 0 评论 0原文

尝试设置Amazon SP-API通知API,但我遇到了一些问题,

我已经设置了所有内容,以创建目的地和SQS订阅。完成该部分后,我现在坚持如何将信息获取到我想要的特定端点。我似乎也无法弄清楚如何通过MFN_Order_status_change传递以从SQS获取所有必要的信息。

Trying to set up Amazon SP-API Notifications Api but I am running into a few issues

I have setup everything up to creating a destination and subscription for SQS. After completing that part, I am now stuck on how to get the information to a specific endpoint that I want. I also cant seem to figure out how will I pass in MFN_ORDER_STATUS_CHANGE to get all the necessary information from the SQS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等待我真够勒 2025-01-29 03:05:12

他们在文档中提到 https://developer-docs.amazon.com/sp-api/docs/notifications-api-v1-use-case-case-guide-guide-guide-guide#step-2-create-a-a-destination

调用创建的操作不需要任何销售合作伙伴的授权。在这方面,此操作是一个“授予”操作,并且与大多数其他销售合作伙伴API操作具有不同的授权模型。

POST https://sellingpartnerapi-na.amazon.com/notifications/v1/destinations
{
  "name": "YourDestinationName",
  "resourceSpecification":
  {
    "sqs":
    {
      "arn": "arn:aws:sqs:us-east-2:444455556666:queue1"
    }
  }
}

https://developer-docs.amazon.amazon.com/amazon-shipping/文档/赠款运行

ToddT, They mention in docs https://developer-docs.amazon.com/sp-api/docs/notifications-api-v1-use-case-guide#step-2-create-a-destination

Calling the createDestination operation does not require authorization from any selling partner. In this respect, this operation is a "grantless" operation and has a different authorization model from most other Selling Partner API operations.

POST https://sellingpartnerapi-na.amazon.com/notifications/v1/destinations
{
  "name": "YourDestinationName",
  "resourceSpecification":
  {
    "sqs":
    {
      "arn": "arn:aws:sqs:us-east-2:444455556666:queue1"
    }
  }
}

https://developer-docs.amazon.com/amazon-shipping/docs/grantless-operations

恋竹姑娘 2025-01-29 03:05:12

AMR,
嘿,我将其放在这里,以便您可以看到我的代码,也许可以看到我在做错了什么。因为我可以像冠军一样使用邮递员。 API的工作原理很好,但是当我翻译自己的代码时,它每次都会失败,我不知道为什么..

在这里。我将在这里放入所有内容,

module CreateSqsSubscriptionService
  module_function
  require 'faraday_middleware/aws_sigv4'

  def call
    @destination_url = "https://sellingpartnerapi-na.amazon.com/notifications/v1/destinations"
    @body = {
      "name": "Todd",
      "resourceSpecification": {
        "sqs": {
          "arn": "arn of the queue I'm setting up"
        }
      }
    }
    get_lwa_access_token
    request_temp_keys
    create_destination
  end

我可以得到LWA访问令牌,就像这样:

  def get_lwa_access_token
    response = Typhoeus.post("https://api.amazon.com/auth/o2/token", body: {
      grant_type: "client_credentials",
      client_id: "lwa id for the app",
      client_secret: "lwa secret for the app",
      scope: "sellingpartnerapi::notifications"
    })
    @access_token = JSON.parse(response.body)["access_token"]
  end

那么这些温度键也很好

def request_temp_keys
sts_client = Aws::STS::Client.new(
  region: "us-east-1",
  credentials: Aws::Credentials.new("ID", "secret")
)

@temp_credentials = sts_client.assume_role({
  role_arn: "arn for SellerAPIRole set in IAM",
  role_session_name: "SPSession"
}).to_h[:credentials]

@temp_credentials #this includes the [:access_key_id] [:secret_access_key] AND [:session_token]
end

,这一切都很好。但这就是失败的地方:

  def create_destination

    conn = Faraday.new(url: 'https://sellingpartnerapi-na.amazon.com') do |faraday|
    faraday.request :aws_sigv4,
            credentials: Aws::Credentials.new(@temp_credentials[:access_key_id], @temp_credentials[:secret_access_key], @temp_credentials[:session_token]),
            service: 'execute-api',
            region: 'us-east-1'
    faraday.adapter Faraday.default_adapter
  end

  response = conn.post('/notifications/v1/destinations') do |req|
      req.headers["x-amz-access-token"] = @access_token
      req.body = @body.to_json
  end

  pp response
 end

是的,我所得到的只是“请求标题中缺少访问令牌”,

但是当我查看请求时,它绝对不会丢失。.喜欢它!

Amr,
Hey, I'm putting this here so you can see my code and maybe see what I'm doing wrong. As I can use postman like a champ. And the API works just fine, but when I translate to my own code it fails every time, and I have no idea why..

Here goes. I'll just put in everything here

module CreateSqsSubscriptionService
  module_function
  require 'faraday_middleware/aws_sigv4'

  def call
    @destination_url = "https://sellingpartnerapi-na.amazon.com/notifications/v1/destinations"
    @body = {
      "name": "Todd",
      "resourceSpecification": {
        "sqs": {
          "arn": "arn of the queue I'm setting up"
        }
      }
    }
    get_lwa_access_token
    request_temp_keys
    create_destination
  end

I can get the LWA access token just fine like this:

  def get_lwa_access_token
    response = Typhoeus.post("https://api.amazon.com/auth/o2/token", body: {
      grant_type: "client_credentials",
      client_id: "lwa id for the app",
      client_secret: "lwa secret for the app",
      scope: "sellingpartnerapi::notifications"
    })
    @access_token = JSON.parse(response.body)["access_token"]
  end

Then these temp keys are great too

def request_temp_keys
sts_client = Aws::STS::Client.new(
  region: "us-east-1",
  credentials: Aws::Credentials.new("ID", "secret")
)

@temp_credentials = sts_client.assume_role({
  role_arn: "arn for SellerAPIRole set in IAM",
  role_session_name: "SPSession"
}).to_h[:credentials]

@temp_credentials #this includes the [:access_key_id] [:secret_access_key] AND [:session_token]
end

Ok, all good to this point. But this is where it fails:

  def create_destination

    conn = Faraday.new(url: 'https://sellingpartnerapi-na.amazon.com') do |faraday|
    faraday.request :aws_sigv4,
            credentials: Aws::Credentials.new(@temp_credentials[:access_key_id], @temp_credentials[:secret_access_key], @temp_credentials[:session_token]),
            service: 'execute-api',
            region: 'us-east-1'
    faraday.adapter Faraday.default_adapter
  end

  response = conn.post('/notifications/v1/destinations') do |req|
      req.headers["x-amz-access-token"] = @access_token
      req.body = @body.to_json
  end

  pp response
 end

Yea all I ever get is "Access token is missing in the request header"

But of course when I look at the request, its definitely NOT missing.. Love it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文