top of page

Get product sales commission with Python x SP-API | Amazon Selling partner API

  • ろびん
  • 2023年7月6日
  • 読了時間: 2分

ree

The Selling Partner API (SP-API) is Amazon's next-generation API suite of automation capabilities for Selling Partners and is an evolution of the Amazon Marketplace Web Service (MWS) API. MWS has provided programmatic access to important Amazon functionality for over a decade. Once the SP-API is live, it will be available in production in all Amazon stores that currently support MWS.

Developers currently using MWS must migrate to SP-API by April 1, 2024. (Information as of January 23, 2023)


Selling Partner API for Product Fees

The Product Fees API allows you to programmatically obtain an estimate of the fees for a product sale. It is useful when setting the price of the product considering the commission.


Environment Preparation

To use SP-API with Python, you need to install the python-amazon-sp-api library. I run python on aws lambda, so I used -t .< /span> option

pip install python-amazon-sp-api -t .

Credentials are required to run the SP-API. Credentials are conveniently stored together in credentials. How to get each value will be introduced in another article.

credentials : {
    "refresh_token":リフレッシュトークン,
    "lwa_app_id":クライアントID,
    "lwa_client_secret": クライアント秘密情報,
    "aws_access_key":AWSアクセスキー,
    "aws_secret_key":AWSシークレットキー
}

API execution

getMyFeesEstimateForSKU Allows you to get the Estimated Fees for Selling Items for a given Merchant SKU in a given Marketplace. By including in your request the amount you want to price your item for, you can know the estimated commission for selling your item before you price your item, which can help you set the selling price.

getMyFeesEstimateForASIN Allows you to get the Estimated Fees for Selling Items for a specified Merchant ASIN in a specified Marketplace. By including in your request the amount you want to price your item for, you can know the estimated commission for selling your item before you price your item, which can help you set the selling price.


getMyFeesEstimateForASIN (Sample)

from sp_api.api import ProductFees
from sp_api.base.marketplaces import Marketplaces
def lambda_handler(event, context):
	#ProductFees利用のためのオブジェクト生成
	obj = ProductFees(marketplace=Marketplaces.JP,
	                   credentials=event['credentials'])
	#検索に必要な値を設定し商品手数料取得イベント情報を取得
	result = obj.get_product_fees_estimate_for_asin(asin='B01LYKJUX6',
						price=1500,
						currency='JPY',
						shipping_price=0,
						is_fba=True)
	return result.payload

Parameter description


Execution result (sample)


{
	"FeesEstimateResult": {
		"Status": "Success",
		"FeesEstimateIdentifier": {
			"MarketplaceId": "A1VC38T7YXB528",
			"IdType": "ASIN",
			"SellerId": "***********",
			"SellerInputIdentifier": "B01LYKJUX6",
			"IsAmazonFulfilled": true,
			"IdValue": "B01LYKJUX6",
			"PriceToEstimateFees": {
				"ListingPrice": {
					"CurrencyCode": "JPY",
					"Amount": 1500
				}
			}
		},
		"FeesEstimate": {
			"TimeOfFeesEstimation": "2023-02-15T01:52:23.000Z",
			"TotalFeesEstimate": {
				"CurrencyCode": "JPY",
				"Amount": 554
			},
			"FeeDetailList": [
				{
					"FeeType": "ReferralFee",
					"FeeAmount": {
						"CurrencyCode": "JPY",
						"Amount": 120
					},
					"FinalFee": {
						"CurrencyCode": "JPY",
						"Amount": 120
					},
					"FeePromotion": {
						"CurrencyCode": "JPY",
						"Amount": 0
					}
				},
				{
					"FeeType": "VariableClosingFee",
					"FeeAmount": {
						"CurrencyCode": "JPY",
						"Amount": 0
					},
					"FinalFee": {
						"CurrencyCode": "JPY",
						"Amount": 0
					},
					"FeePromotion": {
						"CurrencyCode": "JPY",
						"Amount": 0
					}
				},
				{
					"FeeType": "PerItemFee",
					"FeeAmount": {
						"CurrencyCode": "JPY",
						"Amount": 0
					},
					"FinalFee": {
						"CurrencyCode": "JPY",
						"Amount": 0
					},
					"FeePromotion": {
						"CurrencyCode": "JPY",
						"Amount": 0
					}
				},
				{
					"FeeType": "FBAFees",
					"FeeAmount": {
						"CurrencyCode": "JPY",
						"Amount": 434
					},
					"FinalFee": {
						"CurrencyCode": "JPY",
						"Amount": 434
					},
					"FeePromotion": {
						"CurrencyCode": "JPY",
						"Amount": 0
					},
					"IncludedFeeDetailList": [
						{
							"FeeType": "FBAPickAndPack",
							"FeeAmount": {
								"CurrencyCode": "JPY",
								"Amount": 434
							},
							"FinalFee": {
								"CurrencyCode": "JPY",
								"Amount": 434
							},
							"FeePromotion": {
								"CurrencyCode": "JPY",
								"Amount": 0
							}
						}
					]
				}
			]
		}
	}
}





It is easy to understand what each item that can be obtained represents by comparing it with the price simulator of Amazon Seller Central


Let's set some parameters and get the data we need.

 
 
 

© Copyright ROBIN planning LLC.

bottom of page