Comments (13)
So, I cracked this, in case someone wants to refer this.
I used the Website workflow, so bear that in mind.
Step 1: Create a button on your web app that opens an external website as follows:
https://sellercentral.amazon.com/apps/authorize/consent?application_id=&state=abc&version=beta
When you create an app on SP, do not forget to add the Auth URL (not important for website flow) and Redirect URL (very important). Configure this redirect URL to capture and store the fields that come back, most important of which is the spapi_auth_code
Step 2: Once you have stored the spapi_auth_code, fire the following POST request:
https://api.amazon.com/auth/o2/token
Header:
Content-Type=application/x-www-form-urlencoded
Params:
grant_type=authorization_code
code=spapi_auth_code from step 1
client_id=Client ID from the developer app
client_secret=Client Secret from the developer app
redirect_uri= same redirect URI as you have added when creating the app within the SP
You get the Refresh Token back - which is what you will use going forward.
You can use this Refresh Token in the package. :)
from amazon-sp-api.
Hi,
as we haven't implemented the oAuth logic into our own project yet I'm afraid we can't provide that for now. As soon as we have though, we will be happy to include it in the docs. Maybe in the meantime somebody else is around who can share an example.
from amazon-sp-api.
Hey @amz-tools is the library designed to support clients? I've managed to generate the login URL and get back the success codes but I'm struggling with Step 4 - generating a client using the LWA credentials.
Can the library generate LWA refresh tokens? and generate a client using the LWA credentials or am I going to have to use a 3rd party oAuth library to manage this.
from amazon-sp-api.
Hi @StevenJE,
just realising that my last comment probably wasn't very helpful to the original question. :-)
No, its currently not possible with the library. You can only request a LWA authorization code for customers who have authorized you via MWS before. No Oauth logic included yet.
from amazon-sp-api.
No worries! Thanks for the help! :)
from amazon-sp-api.
@Tanveer-LowCoder Legend! Thanks a million.
from amazon-sp-api.
I created a AWS server with the code, available at https://rapidapi.com/user/integrationhub in case anyone wants to quickly test the API. I can add more if required.
from amazon-sp-api.
@Tanveer-LowCoder Just got round to trying to set this up today and I'm getting 500 Internal Sever Errors returned from https://api.amazon.com/auth/o2/token
x-amzn-ErrorType: InternalFailure:http://internal.amazon.com/coral/com.amazon.coral.service/
Do you know if everything is operational on AWS' end?
Heres my code incase it's something I'm doing.
const response = await axios.post("https://api.amazon.com/auth/o2/token", null, {
params: {
grant_type: "authorization_code",
code: "ANmZeXXXXXXXM",
client_id: "amzn1.application-oa2-client.xxxxxxxxxx72",
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
redirect_uri: "https://demo.com/success",
},
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
from amazon-sp-api.
Update: It seems to be something to do with Axios setting Content-Length=0 header by default
What library did you use to make the request?
from amazon-sp-api.
@Tanveer-LowCoder Ugh I'm still stuck on this... any help would be great.
from amazon-sp-api.
@StevenJE I think you called the post method wrong. The second parameter should not be null. This should work:
const response = await axios.post(
"https://api.amazon.com/auth/o2/token",
{
grant_type: "authorization_code",
code: "ANmZeXXXXXXXM",
client_id: "amzn1.application-oa2-client.xxxxxxxxxx72",
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
redirect_uri: "https://demo.com/success",
},
{ headers: { "Content-Type": "application/x-www-form-urlencoded" } }
);
from amazon-sp-api.
@StevenJE I think you called the post method wrong. The second parameter should not be null. This should work:
const response = await axios.post( "https://api.amazon.com/auth/o2/token", { grant_type: "authorization_code", code: "ANmZeXXXXXXXM", client_id: "amzn1.application-oa2-client.xxxxxxxxxx72", client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", redirect_uri: "https://demo.com/success", }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } } );
When I do that I get back the following error as it's being sent as data rather than URL params. The null option is to state that no data is being sent.
data: {
error_description: 'The authorization grant type is not supported by the authorization server',
error: 'unsupported_grant_type'
}
Are you using Axios as well?
from amazon-sp-api.
I use the request module, but tested the axios method before posting it. Unfortunately I did not post the right headers:
{ 'Content-Type':'application/json' }
from amazon-sp-api.
Related Issues (20)
- TS exception HOT 1
- missing productPricing.getCompetitiveSummary from 2022-05-01 version HOT 4
- How can I best get the requestID and timestamp for SP-API support? HOT 1
- getFeed
- Add ability to add error handling middleware HOT 1
- Gracefully handle timeouts HOT 4
- [Bug]`orders.confirmShipment` error on parsing body response
- QueryType = "NEXT_TOKEN" perhaps not being sent to getShipmentItemsByShipmentId?
- Missing timeouts property in DownloadOptions interface HOT 1
- Need order info, tracking number and invoice data
- Is there a way to tell if a seller owns an ASIN or if the seller is a reseller?
- Credentials variables HOT 2
- Incorrect Header Check error downloading file HOT 1
- createFeed with POST_PRODUCT_DATA
- How to get raw request for SP API Developer Support? HOT 2
- Create Offer: Not Update Price, Quantity, and Merchant Shipping Group
- Authorization API v1 Deprecation
- Saving GET_LEDGER_SUMMARY_VIEW_DATA report into database
- Seller Flex Return Report
- new inbound endpoint HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amazon-sp-api.