Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amazon SP-API - Works for everything except for POST #145

Open
Landsailor opened this issue Jun 14, 2022 · 5 comments
Open

Amazon SP-API - Works for everything except for POST #145

Landsailor opened this issue Jun 14, 2022 · 5 comments

Comments

@Landsailor
Copy link

Landsailor commented Jun 14, 2022

Hmmm, describing this may have been enough Duck Debugging to point me to where I need to go... :)

I am nowhere approaching a "JavaScript dev", so I set up a node-red server to handle various Amazon SP-API related duties. This might be an issue with my implementation, function code, or Amazon's Selling Partner API itself.

I created an endpoint that uses aws4 to generate the signature based on query data submitted via a GET, returns it, and is then used for requests in our server. It works for everything except POST requests. Those always return a similar "Close, but no cigar" message from Amazon:
node-red AWS4 POST Signature Error

Here's the function where I have tried enabling and disabling various options to try to get it to work:
node-red AWS4 Function Text
They all return a result similar to the one shown.

When I run the identical request in Postman using the same credentials, it works. However, I noticed that Postman also generates a X-Amz-Content-Sha256 header which is not a hash of the just body text.

Any ideas here? Is there any way to get aws4 to return the Canonical Request and StringToSign for debugging purposes?

Thanks in advance!

@tpietsc1
Copy link

I had a similar issue. I did not get an X-Amz-Content-Sha256 header although the body was provided before signing the request.
To get this work provisionally I made a fork and added my service to this line:

aws4/aws4.js

Line 154 in a413aad

if (this.service === 's3' && !headers['X-Amz-Content-Sha256'] && !headers['x-amz-content-sha256'])

@chyke007
Copy link

Having same issue, works on Postman

@JBetts97
Copy link

Hi,

Did you find a solution to this? Is there another way of getting the X-Amz-Content-Sha256 header?

@chyke007
Copy link

Yes, I did find a solution, I had to sign the body also: https://github.com/chyke007/facial-vote/blob/main/facial-vote-frontend/src/pages/api/vote.ts

@JBetts97
Copy link

Perfect! - Thanks @chyke007 for the quick response! 👍🏻

Glad you found solution. I've also managed to resolve my issue and POST the request using AXIOS library: https://medium.com/@joshua.a.kahn/calling-amazon-api-gateway-authenticated-methods-with-axios-and-aws4-6eeda1aa8696

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants