Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3ea3f2e
Example responses from Amazon for the `Products.get_matching_product_…
Bobspadger Nov 18, 2020
7dd23e2
Initial example of requesting data from Amazon using the `get_matchin…
Bobspadger Nov 18, 2020
88e589c
Example responses from Amazon for the `Products.get_matching_product_…
Bobspadger Nov 18, 2020
50b4175
Initial example of requesting data from Amazon using the `get_matchin…
Bobspadger Nov 18, 2020
efcf8de
initial commit of get_fees.py example file
Bobspadger Dec 18, 2020
e7ec348
Working example of the get_my_fees_estimate along with the resulting XML
Bobspadger Dec 18, 2020
8a5691e
Merge branch 'examples/xml' of github.com:python-amazon-mws/python-am…
Bobspadger Dec 18, 2020
0c5eb65
remove the copy and paste of the find_asin function.
Bobspadger Dec 18, 2020
479e60c
Example responses from Amazon for the `Products.get_matching_product_…
Bobspadger Nov 18, 2020
f86439e
Initial example of requesting data from Amazon using the `get_matchin…
Bobspadger Nov 18, 2020
dcac5a0
initial commit of get_fees.py example file
Bobspadger Dec 18, 2020
019833f
Working example of the get_my_fees_estimate along with the resulting XML
Bobspadger Dec 18, 2020
8e9a8b6
remove the copy and paste of the find_asin function.
Bobspadger Dec 18, 2020
bbe4d8f
Merge branch 'examples/xml' of github.com:python-amazon-mws/python-am…
Bobspadger Mar 18, 2021
cfdc720
initial commit of get_lowest_offer.py example file.
Bobspadger Mar 18, 2021
722325c
working example of get_lowest_offer_listings_for_asin method
Bobspadger Mar 18, 2021
897d9a0
Example responses from Amazon for the `Products.get_matching_product_…
Bobspadger Nov 18, 2020
37ba581
Initial example of requesting data from Amazon using the `get_matchin…
Bobspadger Nov 18, 2020
892e2fb
initial commit of get_fees.py example file
Bobspadger Dec 18, 2020
0fa305a
Working example of the get_my_fees_estimate along with the resulting XML
Bobspadger Dec 18, 2020
38e077d
remove the copy and paste of the find_asin function.
Bobspadger Dec 18, 2020
78a2bf5
initial commit of get_lowest_offer.py example file.
Bobspadger Mar 18, 2021
bc3cac3
working example of get_lowest_offer_listings_for_asin method
Bobspadger Mar 18, 2021
2029eb3
Merge branch 'examples/xml' of github.com:python-amazon-mws/python-am…
Bobspadger Mar 18, 2021
2a03283
fix the last item renamed from products
Bobspadger Mar 18, 2021
6b4366e
flake8
Bobspadger Mar 18, 2021
57ee22c
Example responses from Amazon for the `Products.get_matching_product_…
Bobspadger Nov 18, 2020
4c2406a
Initial example of requesting data from Amazon using the `get_matchin…
Bobspadger Nov 18, 2020
944a949
initial commit of get_fees.py example file
Bobspadger Dec 18, 2020
0060e1a
Working example of the get_my_fees_estimate along with the resulting XML
Bobspadger Dec 18, 2020
2ebc792
remove the copy and paste of the find_asin function.
Bobspadger Dec 18, 2020
c21974a
initial commit of get_lowest_offer.py example file.
Bobspadger Mar 18, 2021
ae167eb
working example of get_lowest_offer_listings_for_asin method
Bobspadger Mar 18, 2021
daccc1c
Working example of the get_my_fees_estimate along with the resulting XML
Bobspadger Dec 18, 2020
43180e3
remove the copy and paste of the find_asin function.
Bobspadger Dec 18, 2020
5b2519d
Working example of the get_my_fees_estimate
Bobspadger Dec 18, 2020
976279f
remove the copy and paste of the find_asin function.
Bobspadger Dec 18, 2020
a063607
fix the last item renamed from products
Bobspadger Mar 18, 2021
66215a7
flake8
Bobspadger Mar 18, 2021
c37fb35
Merge branch 'examples/xml' of https://github.com/python-amazon-mws/p…
GriceTurrble Jun 5, 2021
8b646ba
Merge branch 'develop' into examples/xml
GriceTurrble Dec 13, 2022
3ca2c1e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions examples/find_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os

from mws import Products
from mws.mws import Marketplaces

# You can add your credentials here if you don't want to use environment variables
ACCESS_KEY = None
SECRET_KEY = None
ACCOUNT_ID = None


def find_asin(amazon_type="ASIN", product="B07QR73T66"):
"""
Find a specific product by ASIN - note the use of a list here.

We are setting some defaults for the amazon_type and product here, they are ASIN and the
relevant ASIN for a focusrite saffire audio interface

"""

# Make sure we send a LIST of ids in.
if not isinstance(product, list):
product = [product]

# Call the products api and get find products in amazons catalogue based on our query parameters.
# Notice how we are using our Marketplaces enum to send in the correct marketplace ID
results = products_api.get_matching_product_for_id(
marketplace_id=Marketplaces.UK.marketplace_id, type_=amazon_type, ids=product
)

print(
"ORIGINAL XML RESPONSE - \
use this for debugging or raising issues with - check for confidential information first."
)
print(results.original)

print("The dict like (ObjectDict) response")
print(results.parsed)

# the .parsed node is not guaranteed to be a list so convert it if not.
if not isinstance(results.parsed, list):
found_products = [results.parsed]
else:
found_products = results.parsed

# Output some useful data showing dot notation of the ObjectDict.
for example in found_products:
print("The product title")
print(example.Products.Product.AttributeSets.ItemAttributes.Title)
print("The category")
print(example.Products.Product.SalesRankings.SalesRank[0].ProductCategoryId)
print("The current sales rank")
print(example.Products.Product.SalesRankings.SalesRank[0].Rank)


if __name__ == "__main__":
ACCESS_KEY = os.environ["MWS_ACCESS_KEY"] if ACCESS_KEY is None else ACCESS_KEY
SECRET_KEY = os.environ["MWS_SECRET_KEY"] if SECRET_KEY is None else SECRET_KEY
ACCOUNT_ID = os.environ["MWS_ACCOUNT_ID"] if ACCOUNT_ID is None else ACCOUNT_ID
products_api = Products(
access_key=ACCESS_KEY, secret_key=SECRET_KEY, account_id=ACCOUNT_ID, region="UK"
)
# Find product details via Amazon ASIN
find_asin(amazon_type="ASIN", product="B07QR73T66")
# Find product details via EAN code - note sending this in as a string and also multiple id's
find_asin(amazon_type="EAN", product=["0815301005230", "5060374260160"])
52 changes: 52 additions & 0 deletions examples/get_fees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
from uuid import uuid4

from mws import Products
from mws.models.products import FeesEstimateRequest, MoneyType, PriceToEstimateFees
from mws.mws import Marketplaces

# You can add your credentials here if you don't want to use environment variables
ACCESS_KEY = None
SECRET_KEY = None
ACCOUNT_ID = None


def get_fees():
"""
Get amazon fees estimate for a single product
"""
# Refer to the amazon documentation for this call as it links you through to the models used for
# these calls for more information on what they expect.

# Lets use the models already made in PythonAM
# Refering to the signature for the .get_my_fees_estimate we need the following
# price_to_estimate_fees requires a MoneyType for our price
my_price = MoneyType(amount=123.45, currency_code="GBP")
# This is a MoneyType for shipping which is passed into the price_to_estimate_fees for shipping
my_shipping = MoneyType(amount=0.00, currency_code="GBP")
# Combine the my_price and my_shipping into one PriceToEstimateFees object to send into the API call
my_product_price = PriceToEstimateFees(listing_price=my_price, shipping=my_shipping)
# Create a unique Id for this call (the uuid module is great for this)
my_unique_identifier = str(uuid4())
# Put it all together and send it off to amazon for their response.
my_product = FeesEstimateRequest(
Marketplaces.UK.marketplace_id,
id_type="ASIN",
id_value="B07QR73T66",
price_to_estimate_fees=my_product_price,
is_amazon_fulfilled=False,
identifier=my_unique_identifier,
)
result = products_api.get_my_fees_estimate(my_product)
print(result)


if __name__ == "__main__":
ACCESS_KEY = os.environ["MWS_ACCESS_KEY"] if ACCESS_KEY is None else ACCESS_KEY
SECRET_KEY = os.environ["MWS_SECRET_KEY"] if SECRET_KEY is None else SECRET_KEY
ACCOUNT_ID = os.environ["MWS_ACCOUNT_ID"] if ACCOUNT_ID is None else ACCOUNT_ID
products_api = Products(
access_key=ACCESS_KEY, secret_key=SECRET_KEY, account_id=ACCOUNT_ID, region="UK"
)
# get fees for a single product
get_fees()
61 changes: 61 additions & 0 deletions examples/get_lowest_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os

from mws import Products
from mws.mws import Marketplaces

# You can add your credentials here if you don't want to use environment variables
ACCESS_KEY = None
SECRET_KEY = None
ACCOUNT_ID = None


def find_asin_lowest_offer(search_asins="B07QR73T66"):
"""
Find a specific product by ASIN - note the use of a list here.

We are setting some defaults for the amazon_type and product here, they are ASIN and the
relevant ASIN for a focusrite saffire audio interface

"""

# Make sure we send a LIST of ids in.
if not isinstance(search_asins, list):
search_asins = [search_asins]

# Call the products api and get find products in amazons catalogue based on our query parameters.
# Notice how we are using our Marketplaces enum to send in the correct marketplace ID
results = products_api.get_lowest_offer_listings_for_asin(
marketplace_id=Marketplaces.UK.marketplace_id, asins=search_asins
)

print(
"ORIGINAL XML RESPONSE - \
use this for debugging or raising issues with - check for confidential information first."
)
print(results.original)

print("The dict like (ObjectDict) response")
print(results.parsed)

# the .parsed node is not guaranteed to be a list so convert it if not.
if not isinstance(results.parsed, list):
found_products = [results.parsed]
else:
found_products = results.parsed

# Output some useful data showing dot notation of the ObjectDict.
for result in found_products:
lowest_listings = result.Product.LowestOfferListings.LowestOfferListing
for lowest_offer in lowest_listings:
print(lowest_offer)


if __name__ == "__main__":
ACCESS_KEY = os.environ["MWS_ACCESS_KEY"] if ACCESS_KEY is None else ACCESS_KEY
SECRET_KEY = os.environ["MWS_SECRET_KEY"] if SECRET_KEY is None else SECRET_KEY
ACCOUNT_ID = os.environ["MWS_ACCOUNT_ID"] if ACCOUNT_ID is None else ACCOUNT_ID
products_api = Products(
access_key=ACCESS_KEY, secret_key=SECRET_KEY, account_id=ACCOUNT_ID, region="UK"
)
# Find product details via Amazon ASIN
find_asin_lowest_offer(search_asins="B07QR73T66")
84 changes: 84 additions & 0 deletions tests/xml_examples/get_fees_estimate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<GetMyFeesEstimateResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetMyFeesEstimateResult>
<FeesEstimateResultList>
<FeesEstimateResult>
<FeesEstimate>
<TimeOfFeesEstimation>2020-12-18T11:53:53.712Z</TimeOfFeesEstimation>
<TotalFeesEstimate>
<Amount>15.11</Amount>
<CurrencyCode>GBP</CurrencyCode>
</TotalFeesEstimate>
<FeeDetailList>
<FeeDetail>
<FeeAmount>
<Amount>15.11</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FeeAmount>
<FinalFee>
<Amount>15.11</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FinalFee>
<FeePromotion>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FeePromotion>
<FeeType>ReferralFee</FeeType>
</FeeDetail>
<FeeDetail>
<FeeAmount>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FeeAmount>
<FinalFee>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FinalFee>
<FeePromotion>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FeePromotion>
<FeeType>VariableClosingFee</FeeType>
</FeeDetail>
<FeeDetail>
<FeeAmount>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FeeAmount>
<FinalFee>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FinalFee>
<FeePromotion>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</FeePromotion>
<FeeType>PerItemFee</FeeType>
</FeeDetail>
</FeeDetailList>
</FeesEstimate>
<FeesEstimateIdentifier>
<MarketplaceId>A1F83G8C2ARO7P</MarketplaceId>
<IdType>ASIN</IdType>
<SellerId>A27DY0XIZK94N5</SellerId>
<IsAmazonFulfilled>false</IsAmazonFulfilled>
<SellerInputIdentifier>fb24c3ff-b0b5-4125-9f15-77f15f886192</SellerInputIdentifier>
<IdValue>B07QR73T66</IdValue>
<PriceToEstimateFees>
<ListingPrice>
<Amount>123.45</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ListingPrice>
<Shipping>
<Amount>0.0</Amount>
<CurrencyCode>GBP</CurrencyCode>
</Shipping>
</PriceToEstimateFees>
</FeesEstimateIdentifier>
<Status>Success</Status>
</FeesEstimateResult>
</FeesEstimateResultList>
</GetMyFeesEstimateResult>
<ResponseMetadata>
<RequestId>c1788273-8c80-4805-8a59-5eb512d7b0e9</RequestId>
</ResponseMetadata>
</GetMyFeesEstimateResponse>
Loading