设置 Amazon SP-API 通知 API

问题描述 投票:0回答:3

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

我已设置好一切,为 SQS 创建目标和订阅。完成该部分后,我现在陷入如何将信息发送到我想要的特定端点的问题。我似乎也不知道如何传递 MFN_ORDER_STATUS_CHANGE 来从 SQS 获取所有必要的信息。

amazon-sqs amazon-sns amazon-selling-partner-api
3个回答
1
投票

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

调用createDestination操作不需要任何销售伙伴的授权。在这方面,此操作是“无授权”操作,并且具有与大多数其他销售合作伙伴 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.com/amazon-shipping/docs/grantless-operations


0
投票

阿姆尔, 嘿,我把它放在这里,这样你就可以看到我的代码,也许还能看到我做错了什么。因为我可以像冠军一样使用邮递员。 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

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

但是当然,当我查看请求时,它绝对没有丢失..喜欢它!


0
投票

嘿,您是否想出任何方法可以从 SQS 向任何端点发送这些通知?

© www.soinside.com 2019 - 2024. All rights reserved.