首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置Amazon API通知API

设置Amazon API通知API
EN

Stack Overflow用户
提问于 2022-04-18 15:54:38
回答 2查看 655关注 0票数 2

试图设置Amazon Api通知,但我遇到了一些问题。

我已经为SQS设置了一切,直到创建目标和订阅。在完成该部分之后,我现在只能继续讨论如何将信息发送到我想要的特定端点。我似乎也不知道如何通过MFN_ORDER_STATUS_CHANGE从SQS获取所有必要的信息。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-05-18 08:22:15

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

调用createDestination操作不需要任何销售伙伴的授权。在这方面,此操作是“无赠款”操作,与大多数其他销售合作伙伴API操作具有不同的授权模型。

代码语言:javascript
复制
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

票数 1
EN

Stack Overflow用户

发布于 2022-05-15 21:50:51

Amr,嘿,我把这个放在这里,这样你就可以看到我的代码,也许可以看看我做错了什么。因为我可以像个冠军一样利用邮递员。API运行得很好,但是当我把它转换成我自己的代码时,每次都会失败,我不知道为什么。

开始吧。我把所有的东西都放进去

代码语言:javascript
复制
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访问令牌,就像这样:

代码语言:javascript
复制
  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

那么这些临时钥匙也很棒

代码语言:javascript
复制
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

好吧,现在一切都很好。但这正是它失败的地方:

代码语言:javascript
复制
  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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71914075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档