saleweaver / python-amazon-sp-api Goto Github PK
View Code? Open in Web Editor NEWPython wrapper to access the amazon selling partner API
Home Page: https://python-amazon-sp-api.readthedocs.io/en/latest/
License: MIT License
Python wrapper to access the amazon selling partner API
Home Page: https://python-amazon-sp-api.readthedocs.io/en/latest/
License: MIT License
feeds.Feeds(marketplace=Marketplaces.US,credentials=credentials).submit_feed(feed_type='str' ,file='SKU-12345\tLyric 500 tc Queen Flat Sheet, Ivory\t17.8\t50\tnew', content_type='text/tsv')
or i am calling with xml file
feeds.Feeds(marketplace=Marketplaces.US,credentials=credentials).submit_feed(feed_type='str' ,file='feed.txt', content_type='text/tsv')
and my xml file is
feed.txt
in both of the calling function i am getting same error
In our company we have 2 different accounts, one for European market and one for US.
Do you think is possible to pass environment variables as params to the library ?
Hi,
I tried to run
this code:
try:
res = Orders().get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
print(res.payload) # json data
except SellingApiException as ex:
print(ex)
the error I get is [{'message': "Credential should be scoped to a valid region, not 'us-east-1'. ", 'code': 'InvalidSignature'}]
I also tried to change region but the error is the same:
[{'message':** "Credential should be scoped to a valid region, not 'eu-central-1'. ", 'code': 'InvalidSignature'}]
Can you help me?
I have seen in the api model info about GetOrderAddressResponse but in current release of your project there's no any call for it.
Do you are planning to develop it ?
#21
I added a new api to get the inventory summaries, would be great if u can merge it please :)
Describe the bug
When I run the sample code it's saying that an unexpected keyword argument credentials.
To Reproduce
from datetime import datetime, timedelta
from sp_api.api import Orders
from sp_api.base import SellingApiException
credentials= dict(
refresh_token='Atzr|XXXXXXX',
lwa_app_id='amzn1.application-oa2-client.XXXXXXXX',
lwa_client_secret='XXXXXXXXXX',
aws_secret_key='XXXXXXXXXXXXX',
aws_access_key='XXXXXXXXXXXX',
role_arn='arn:aws:iam::XXXXXXXXX',
)
Orders(credentials=credentials).get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
Expected behavior
I ran it yesterday and that was okay.
But now running on different pc. I am getting this error
Desktop (please complete the following information):
Windows
Additional context
I installed the latest module using pip
when u will create Class of this endpoint api?
https://github.com/amzn/selling-partner-api-docs/blob/main/references/fulfillment-outbound-api/fulfillmentOutbound_2020-07-01.md
Hi Michael,
kann man dich mit Test Ergebnissen aus dem FBA Alltag unterstützen?
Mir ist gerade noch nicht ganz klar wie man die library einbinden soll aber wenn ich mir den weg durch den IAM Dschungel dadurch ersparen kann helfe ich gerne mit die Entwicklung voran zu treiben.
This is my code:
from sp_api import api
credentials=dict(
refresh_token='XXXXXX',
lwa_app_id='XXXXXX',
lwa_client_secret='XXXXXX',
aws_secret_key='XXXXXX',
aws_access_key='XXXXXX',
role_arn='XXXXXX',
)
response = api.Products(credentials=credentials).get_product_pricing_for_asins(asin_list="B08PTV374B")`
The only thing I can figure is that I'm using the wrong value somewhere.
I've verified all of the keys, tokens, and secrets several times:
refresh_token: I am using the refresh token given by selecting Authorize in the Edit App dropdown in developer central
lwa_app_id: I have tried both the App Id next to the name of the app in developer central and Client identifier from the LWA credentials pop up.
lwa_client_secret: I'm using the Client secret from the LWA credentials pop up.
aws_secret_key: I'm using the secret key created during the IAM steps of the docs
aws_access_key: I'm using the access key created during the IAM steps of the docs.
role_arn: I'm using the arn from the role created during the IAM steps of the docs.
EDIT:
This is the response I'm getting:
(<class 'sp_api.base.exceptions.SellingApiForbiddenException'>, SellingApiForbiddenException([{'message': 'Access to requested resource is denied.', 'code': 'Unauthorized', 'details': 'Access token is missing in the request header.'}]), <traceback object at 0x7f21e94e4688>)
i am requesting
feeds.Feeds(marketplace=Marketplaces.US,credentials=credentials).get_feed_result_document(feed_id
='50171018682')
and i am getting this error
[{'code': 'InvalidInput', 'message': 'Invalid request parameters', 'details': ''}]
i have uploaded the data and getting the response using the get_feed()
feedDocumentId.txt
I was thinking of adding a variable in the env to say if its a sandbox or not, and then inside of the Marketplaces enum I will choose the urls depending if its sandbox or not. Would that be okay with you ?
Can get the refresh token just fine, but getting [{'message': 'Access to requested resource is denied.', 'code': 'Unauthorized', 'details': ''}]
for any API request I make.
Any idea on what might be happening?
Do you think it would be possible to extract what marketplace he did choose while authorising from the user token ?
Hi,
I got issue and don't know have i missed any steps?
{'message': 'Access to requested resource is denied.', 'code': 'Unauthorized', 'details': ''}
Request
import datetime
from sp_api import api
from sp_api import base
from sp_api import auth
credentials=dict(
refresh_token='xxx',
lwa_app_id='xxx',
lwa_client_secret='xxx',
aws_secret_key='xxx',
aws_access_key='xxx',
role_arn='xxx',
)
createReportResponse = api.Reports(credentials=credentials).create_report(reportType='GET_FLAT_FILE_OPEN_LISTINGS_DATA')
I want to access the inventory data of my seller account and by accessing the Inventories end point it is only giving inventory data of fulfillment by amazon data not fulfillment by merchant.
can you please tell me how to get inventory data of fulfillment by merchant?
Thank you
Is it possible to not require the Assume Role permission for the role arn if the role has sufficient permission already? The role I'm using is the role that would "be assumed."
After a lot of troubleshooting with sp-api support, we found that the assume role permission was causing my API requests to fail. After removing the permission, I'm now able to write successful requests. That said, I would prefer to start working with this library.
Here's the error message I'm currently receiving:
ClientError: An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::72750xxxxxxx:user/spxxxx is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::72750xxxxxxx:user/spxxxx
Let me know if any of this doesn't make sense.
For some reason this commit here didn't go in version 0.1.2
c42ff0a#diff-fc7273734daad993dc59ccc3a0a8748fab5c950f560990bf70be387c6a8ccd2dL15
when I upgraded to 0.1.2 I got these print statements
o.s: Debian
python rel: 3.5
Code to reproduce the errore:
""""""""
from datetime import datetime, timedelta
from sp_api.api import Orders
from sp_api.base import SellingApiException
try:
res = Orders().get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=1)).isoformat())
print(res.payload) # json data
except SellingApiException as ex:
print(ex)
"""""""""""
I'm requesting by following code.
inventoryClient = api.Inventories(credentials=self.credentials, marketplace=Marketplaces.JP)
res = inventoryClient.get_inventory_summary_marketplace(sellerSkus=['sku1', 'sku2'])
Then I'm getting error.
sp_api.base.exceptions.SellingApiForbiddenException: [{'message': 'Access to requested resource is denied.', 'code': 'Unauthorized', 'details': ''}]
However my credentials is correct.
Other API(feed, report...) is working.
Please help me.
Describe the bug
I am trying to get order metrics from the Sales model
and I am getting an error
[{'message': 'Missing or invalid request parameters: [marketplaceIds]', 'code': 'InvalidInput'}]
To Reproduce
Steps to reproduce the behavior:
from sp_api.api import Sales
from sp_api.base import Granularity
sales = Sales()
sales.get_order_metrics(interval=((datetime.utcnow() - timedelta(days=7)).isoformat(), datetime.utcnow().isoformat()),
granularity=Granularity.DAY)
I try to use get_competitive_pricing_for_skus call but I receive the error
[{'message': 'Required parameter SellerSKU not found', 'code': 'InvalidInput', 'details': ''}]
My call example:
res = Products(
credentials=credentials,
marketplace=mkt
).get_competitive_pricing_for_skus(
seller_sku_list=[
'LA-19411',
]
)
Which API - Endpoint is your request about.
I need the information returned by this API call: getOrderItemsBuyerInfo
Additional context
I have made the change on a local version but not certain on the protocol for adding this as a PR. Pretty simple change to orders.py
Describe the bug
When calling the Feeds.submit_feed() it results eventually in an error at Amazon Sellercentral.
Feed Processing Summary:
Number of records processed 0
Number of records successful 0
original-record-number sku error-code error-type error-message
0 90011 Fatal The file's column headings are missing or invalid. To correct this error, download the template again and use that new copy, or insert the correct column headings as row two of your existing file.
To Reproduce
Steps to reproduce the behavior:
Run this file.
main.zip
Expected behavior
A "Correct" processed file on Amazon Seller Central. No Technical Errors.
Desktop (please complete the following information):
Additional context
Using Python 3.8
On windows in a clean virtual ENV with just sp-api installed, nothing more.
Using the below code I keep returning:
[{'code': 'Unauthorized', 'message': 'Access to the resource is forbidden', 'details': ''}]
No issues with my auth and credentials as I can pull the orders using Orders().get_orders fine.
from sp_api.api import Reports
from sp_api.base import Marketplaces
from sp_api.base import SellingApiException
from datetime import datetime, timedelta
startdate = datetime.now().isoformat()
enddate = (datetime.now() - timedelta(days=30)).isoformat()
try:
CreateReportResponse = Reports(marketplace=Marketplaces.GB).create_report(reportType='GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE',data_start_time=startdate,data_end_time=enddate)
except SellingApiException as ex:
print(ex)
thank you soo much brother u help me a lot
please help me in shorting this out
why i am getting this error while uploading the feed data my calling function
Feeds(marketplace=Marketplaces.US,credentials=credentials).submit_feed(feed_type='str' ,file=open('feed2.txt'), content_type='text/tsv')
i am getting this error
[{'code': 'InvalidInput', 'message': "1 validation error detected: Value '[]' at 'marketplaceIdList' failed to satisfy constraint: Member must have length greater than or equal to 1", 'details': ''}]
is my feed data formate is right? if u please give me an example of feeds data file than it help me a lot
feed.txt
feed2.txt
How can I change the parameter "x-amzn-ratelimit-limit" in this module? I now encounter the problem of "[{message ':'You exceeded your quota for the requested resource.','code ':'quotaexceeded'}]"
I have an order from the UK marketplace in which I am sure there should be information relating to the TaxCollection, but I don't understand why I cannot read it in the "get_order_items" call.
Hi, I would find useful to have the operation getReports (Endpoint: GET /reports/2020-09-04/reports), https://github.com/amzn/selling-partner-api-docs/blob/main/references/reports-api/reports_2020-09-04.md#getreports
Basically you get a list of reports that meet the specifications you have given
Do you think is feasible?
Any plans for a Discord/Slack channel related to this repo?
Describe the bug
When I run the sample code in the readme.md, it doesn't succeed.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
I try to get listing offer for some items with blank space or / in sku
res = Products(
credentials=credentials,
marketplace=mkt
).get_listing_offers(
seller_sku= "MS-S6-35036/WH" ,
ItemCondition = 'New',
)
I receive error "Access to requested resource is denied."
Hi Currently struggling on where to obtain all the credential keys:
refresh_token: ''
lwa_app_id: ''
lwa_client_secret: ''
aws_secret_key: ''
aws_access_key: ''
role_arn: ''
Can you provide documentation/guidance on where these are obtained from.
I'm receiving an error
[{'message': 'Access to requested resource is denied.', 'code': 'Unauthorized', 'details': 'Access token is missing in the request header.'}]
on any request I make (checked on getMarketPlaceParticipation and getOrders). And there is no method to pass an access_token.
The exceed quota exception is not throwing information about the request.
it is missing : x-amzn-RateLimit-Limit
Based on the following documentation, the information will allow better api request and usage of the rate limit.
I have been getting this error for every request. I currently have a Seller Central account and I am trying to gain access to the api. I have followed the documentation provided by amazon to set up the necessary credentials, but still receive the 'Access to requested resource is denied.' error message. I have checked in on the access_token that is being generated and it matches the 'Atza|xxxxxx' format, so I do not believe that is the issue.
Additionally, I have been following the Self Authorization guidelines to get the refresh token used here, so I am unsure as to why I am getting the error.
I have searched through the issues here and under the Seller-partner-api-docs and found no solution.
from sp_api.api.orders.orders import Orders
os.environ["SP_API_REFRESH_TOKEN"] = "Atzr|xxxxxxxx"
os.environ["LWA_APP_ID"] = "amzn1.application-oa2-client.xxxxxxxx"
os.environ["LWA_CLIENT_SECRET"] = "xxxxxxxx"
os.environ["SP_API_SECRET_KEY"] = "xxxxxxxx"
os.environ["SP_API_ACCESS_KEY"] = "xxxxxxxx"
os.environ["SP_API_ROLE_ARN"] = "arn:aws:iam::xxxxxxxx:role/SellerPartnerAPIRole"
os.environ["SP_AWS_REGION"] = "us-east-1"
try:
res = Orders().get_orders(CreatedAfter=(datetime.datetime.utcnow() - datetime.timedelta(days=7)).isoformat())
print(res.payload) # json data
except SellingApiException as ex:
print(ex)
output
{'Date': 'Wed, 27 Jan 2021 15:22:51 GMT', 'Content-Type': 'application/json', 'Content-Length': '141', 'Connection': 'keep-alive', 'x-amzn-RequestId': '387bf5b0-58c6-4dee-93a0-47c3da1fadc0', 'x-amzn-ErrorType': 'AccessDeniedException', 'x-amz-apigw-id': 'Z0HDvHjOoAMF0Aw='}
{'errors': [{'message': 'Access to requested resource is denied.', 'code': 'Unauthorized', 'details': ''}]}
[{'message': 'Access to requested resource is denied.', 'code': 'Unauthorized', 'details': ''}]
Any help will be greatly appreciated!
Could you add the new report type ?
https://github.com/amzn/selling-partner-api-docs/issues/568
thanks
Alessandro
Hi,
First thanks for this project.
Could you add shipping api or explain how to add it to the project?
This is the reference: https://github.com/amzn/selling-partner-api-docs/tree/main/references/shipping-api
Hi,
we have communication problem with amazon.
Our client logs in to our service where he clicks button "Log in Amazon". He is then redirected to url https://sellercentral.amazon.pl/apps/authorize/consent?application_id=amzn1.sellerapps.app.xxxx-xxxx-xxx-xxx-xxx&state=here_is_unique_uid. On this page our partner accepts the usage for our application and is redirected back, from that action we get selling_partner_id and spapi_oauth_code. After that we send request on https://api.amazon.com/auth/o2/token with data:
{'grant_type': "authorization_code",
'code': spapi_oauth_code,
'redirect_uri': redirect_url,
'client_id': AMAZON_CLIENT_ID,
'client_secret': AMAZON_SECRET
}
where AMAZON_CLIENT_ID and AMAZON_SECRET are LWA credentials of app. In response we receive access_token and refresh token. Till this point everything works fine.
Now we try to get orders data:
1.
We request Login with Amazon access token on /auth/o2/token with params: client_id, client_secret (LWA credentials of app) grant_type=refresh_token, refresh_token=refresh token we have from previous step. In response we receive new access_token and refresh_token.
We create assume role request on sts.amazonaws.com using AWS_ACCESS from AWS for credential and AWS_SECRET from AWS for computing signature. From that response we get SessionToken and accesskeyid.
Final request for orders: GET on sellingpartnerapi-eu.amazon.com/orders/v0/orders in Authorization header for credential we use accesskeyid from assume role request, for X-Amz-Access-Token header we use access token from 1st request, and for X-Amz-Security-Token we send sessiontoken received from assumrole request for that data we receive 403 forbidden error
HTTP/2.0 403 Forbidden
Content-Length: 141
Content-Type: application/json
Date: Wed, 07 Apr 2021 13:33:57 GMT
X-Amz-Apigw-Id: daku6GYXDoEFQPw=
X-Amzn-Errortype: AccessDeniedException
X-Amzn-Requestid: 55ff0680-a7c1-412d-830d-cc3b018ea1b9
{
"errors": [
{
"message": "Access to requested resource is denied.",
"code": "Unauthorized",
"details": ""
}
]
}
We don't have idea what is wrong. Our app have a access permission to get order.
I'm getting data through the Finances API, but when I pass in the next_token page flip, it returns exactly the same data as the previous page.
(The different Next_Tokens return exactly the same data)
Did I get it wrong?
Helpppppppppppppppppppppppppppppppppppppppp!
Which API - Endpoint is your request about.
All API endpoints
Additional context
Here is how it any API call fails when throttle limit reached:
------> sp_api.base.client.SellingApiException: [{'message': 'You exceeded your quota for the requested resource.', 'code': 'QuotaExceeded'}]
Probably need to add some "re-trying" right in this library. Or maybe add an Exception handling...
Hello,
Amazon never returns the phone field when I call get_order_address().
It returns all other info like "AddressLine1", "City", "CountryCode", "Name", "PostalCode", "StateOrRegion", and also "AddressLine2" if present, but never the phone.
This happens in both cases when we have AFN e MFN. (As specified in the documentation, this should't be returned only for Fulfillment by Amazon (FBA) orders.)
I have all the PII authorization setted. I also tried using a restricted data token but also in this case the phone field is not present.
Thanks in advance.
getting error in feed api
feeds.Feeds(marketplace=Marketplaces.US,credentials=credentials).submit_feed(feed_type='str' ,file=open('feed2.txt'), content_type='text/tsv')
uploading the file
feed3.txt
feed.txt
feed2.txt
among above three feed file which one is correctly configured and also can u please give me the format of feed data file can be very helpful
Hi!
So basically, my question is in summary.
I have application that was registered with User ARN. Should different approach be used if application is registered with User ARN?
Can I still use this package? Thx!
Describe the bug
When Reports API returns gzipped document, it looks like content is corrupted.
To Reproduce
when the report document is too big, it adds gzip compression. But then can't open that archive...
Reports().create_report(reportType='GET_XML_BROWSE_TREE_DATA')
Expected behavior
Maybe need to gunzip first and then AES-decode? Or maybe just a bug with AES decoder...
Desktop (please complete the following information):
Hi,
I cannot get orders from different Marketplaces all in once.
If I call get_orders(MarketplaceIds=["APJ6JRA9NG5V4"])
I correctly get the amazon IT orders.
Also if I call get_orders(MarketplaceIds=["A1PA6795UKMFR9"])
I correctly get the amazon DE orders.
But when I try pass the list of marketplaceIds it just returns the orders from the first marketplace.
For example if I call get_orders(MarketplaceIds=["APJ6JRA9NG5V4", "A1PA6795UKMFR9"])
it returns only the IT orders.
In particular my code is this: res = Orders(credentials=credentials, marketplace=Marketplaces.IT).get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=time_step_in_days)).isoformat(), MarketplaceIds=["APJ6JRA9NG5V4", "A1PA6795UKMFR9"])
How can I solve?
Thanks in advice.
Hello, I found that there is no fulfillment-outbound-api in the project. Will it be updated later?
Hi, could you provide the code to initialize the requests?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.