Does we have the option to add product to amazon seller account through API?

79 Views Asked by At

I need the API to create product on Amazon Seller account from API for a python project. How to do that. Can anyone please help.

1

There are 1 best solutions below

2
Hugo Barona On BEST ANSWER

Yes, Amazon provides an API called the Amazon Marketplace Web Service (Amazon MWS) that allows you to programmatically manage your Amazon Seller account, including adding products. Here's a brief overview of the steps you need to take:

  • Register for Amazon MWS:

    • Go to the Amazon MWS Developer Portal.
    • Sign in with your existing Amazon Seller Central account or create a new one.
    • Complete the registration process for Amazon MWS.
  • Access API Keys:

    • After registration, go to the Amazon MWS Developer Access Keys page to obtain your Access Key ID and Secret Access Key.
  • Choose the Appropriate API Section:

  • The operations related to managing products (including adding) fall under the "Feeds" section of the Amazon MWS API.

  • Use the SubmitFeed Operation:

    • The SubmitFeed operation is used to submit product information to Amazon. You need to create a feed file containing product data and use this operation to upload the file.
  • Feed Types for Products:

    • For adding products, you typically use feed types like POST_PRODUCT_DATA or POST_FLAT_FILE_LISTINGS_DATA. The choice depends on the format of the data you're submitting (XML or flat file).
  • Make API Requests:

  • Sign Requests:

    • Sign your requests using your Access Key ID and Secret Access Key. The signature is crucial for authentication.
  • Handle Responses:

    • Process the responses returned by the API to determine if the product data was successfully submitted.

Here is some sample code on how to do it (replace placeholders like 'YourAccessKey', 'YourSecretKey', etc., with your actual Amazon MWS credentials and data):

import requests
import hashlib
import base64
import hmac
import time

def generate_amazon_mws_signature(secret_key, service_url, params):
    canonical_query_string = '&'.join([f'{key}={params[key]}' for key in sorted(params)])
    string_to_sign = f"POST\n{service_url}\n/\n{canonical_query_string}"

    signature = base64.b64encode(hmac.new(secret_key.encode(), string_to_sign.encode(), hashlib.sha256).digest()).decode()
    return signature

def submit_feed(access_key, secret_key, merchant_id, marketplace_id, feed_type, feed_content):
    service_url = 'https://mws.amazonservices.com'
    endpoint = '/Feeds/2009-01-01'

    params = {
        'AWSAccessKeyId': access_key,
        'Action': 'SubmitFeed',
        'Merchant': merchant_id,
        'MWSAuthToken': 'YourMWSAuthToken',  # If applicable
        'FeedType': feed_type,
        'MarketplaceIdList.Id.1': marketplace_id,
        'PurgeAndReplace': 'false',  # Set to 'true' if you want to replace existing data
        'SignatureMethod': 'HmacSHA256',
        'SignatureVersion': '2',
        'Timestamp': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
        'Version': '2009-01-01',
    }

    signature = generate_amazon_mws_signature(secret_key, service_url + endpoint, params)
    params['Signature'] = signature

    headers = {'Content-Type': 'text/xml'}

    response = requests.post(f'{service_url}{endpoint}', params=params, headers=headers, data=feed_content)

    # Process the response as needed
    print(response.text)

# Example usage
access_key = 'YourAccessKey'
secret_key = 'YourSecretKey'
merchant_id = 'YourMerchantID'
marketplace_id = 'YourMarketplaceID'
feed_type = '_POST_PRODUCT_DATA_'  # Or other appropriate feed type
feed_content = 'YourFeedContent'  # Actual product data in XML or flat file format

submit_feed(access_key, secret_key, merchant_id, marketplace_id, feed_type, feed_content)

If you want to learn more about it, use the link below

https://docs.developer.amazonservices.com/en_US/dev_guide/index.html