Config File

An example config file is provided in this repository, it supports multiple accounts. The programm looks for a file called credentials.yml [1]

The config is parsed by confused [2], see their docs for more in depth information. Search paths are:

macOS: ~/.config/python-sp-api
Other Unix: ~/.config/python-sp-api
Windows: %APPDATA%\python-sp-api where the APPDATA environment variable falls back to %HOME%\AppData\Roaming if undefined

If you’re only using one account, place it under default. You can pass the account’s name to the client to use any other account used in the credentials.yml [1] file.

Note

Required fields are:

  • lwa_app_id

  • lwa_client_secret

If you don’t set the refresh_token, you have to pass it to the client.

Orders(refresh_token='...')
version: '1.0'

default:
  refresh_token: ''
  lwa_app_id: ''
  lwa_client_secret: ''

another_account:
  refresh_token: ''
  lwa_app_id: ''
  lwa_client_secret: ''

Usage with default account

Orders().get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())

Usage with another_account

You can use every account’s name from the config file for account

Orders(account=another_account).get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())

Note

The refresh token can be passed directly to the client, too. You don’t need to pass the whole credentials if all that changes is the refresh token.

Orders(account='another_account', refresh_token='<refresh_token_for_this_request>').get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())

References