Search code examples
pythonswagger-codegenamazon-selling-partner-api

Amazon sp-api. Authentication with old MWS tokens with swagger generated code


I am trying connect to Amazon using new sp-api and Hybrid approach. I took here the model and "compile" it with swagger. Then I try to execute the example code:

from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint

# create an instance of the API class
api_instance = swagger_client.AuthorizationApi(swagger_client.ApiClient(configuration))
selling_partner_id = 'selling_partner_id_example' # str | The seller ID of the seller for whom you are requesting Selling Partner API authorization. This must be the seller ID of the seller who authorized your application on the Marketplace Appstore.
developer_id = 'developer_id_example' # str | Your developer ID. This must be one of the developer ID values that you provided when you registered your application in Developer Central.
mws_auth_token = 'mws_auth_token_example' # str | The MWS Auth Token that was generated when the seller authorized your application on the Marketplace Appstore.

try:
    # Returns the Login with Amazon (LWA) authorization code for an existing Amazon MWS authorization.
    api_response = api_instance.get_authorization_code(selling_partner_id, developer_id, mws_auth_token)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling AuthorizationApi->get_authorization_code: %s\n" % e)

but I receive the error message:

Exception when calling AuthorizationApi->get_authorization_code: (403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 03 Jun 2021 15:45:52 GMT', 'Content-Type': 'application/json', 'Content-Length': '135', 'Connection': 'keep-alive', 'x-amzn-RequestId': '6b00b699-2ce1-4973-a155-d7ecee9d7f7b', 'x-amzn-ErrorType': 'MissingAuthenticationTokenException', 'x-amz-apigw-id': 'AWvfqFUmoAMF6Yg='})
HTTP response body: {
  "errors": [
    {
      "message": "Access to requested resource is denied.",
     "code": "MissingAuthenticationToken"
    }
  ]
}

Some people says NEED HEADER but in documentation is nothing about it.

So my question is: How to authorize, using MWS old token??


Solution

  • The answer is heare

    Detail explanation of handmade request authoritarian )

    When my code will works I'll place it here.