试图设置Amazon Api通知,但我遇到了一些问题。
我已经为SQS设置了一切,直到创建目标和订阅。在完成该部分之后,我现在只能继续讨论如何将信息发送到我想要的特定端点。我似乎也不知道如何通过MFN_ORDER_STATUS_CHANGE从SQS获取所有必要的信息。
发布于 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操作具有不同的授权模型。
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
发布于 2022-05-15 21:50:51
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是的,我得到的只是“请求头中缺少访问令牌”。
但当然,当我看到这个请求时,它绝对不会丢失..。爱死它了!
https://stackoverflow.com/questions/71914075
复制相似问题