Create and update tariffs

You need to have an access token so you can create or update tariffs.
The steps to get a token are described here: How to get your token.

Once you are authenticated, you can retrieve your tariffs. The Tariffs are described in the following chapter : Understanding tariffs

Create a tariff in 5 mins

First, connect on SupplierXM and go to your profile, create a new access key.

❗️

Don't forget to copy your client secret before closing the modal, you won't be able to get it later.

Let's first get the access token.

import json
import requests

# Data for authentication, update it with your own credential
authentication_payload = {
    "client_id": "{your client id}",  # replace with your client id
    "client_secret": "{your client secret}",  # replace with your client secret
    "grant_type": "client_credentials",
}

# Call the authentication API
response = requests.post(
    "https://apis.supplierxm.salsify.com/auth/v2/token",
    data=json.dumps(authentication_payload)
).json()

# Response contains:
# {"access_token": "{your access token}", "type": "JWT"}

access_token = response['access_token']

# We will use this access_token to access SupplierXM APIS
headers = {
    'Authorization': 'Bearer %s' % access_token,
  	'Content-Type': 'application/json',  # We will be using json
}

Now that you have your access token, let's create a tariff and store its uuid.
You can create or update tariffs using the https://apis.supplierxm.salsify.com/public/v1/tariffs API. Its reference is available here: Tariff update.

tariff = {
    # data is an array because the API allows you to create/update
    # multiple tariffs at once
    "data": [
        {
            "data": {
                "orderStartDate": "2019-05-17",
                "targetCountryList": [
                    {"targetCountryCode": {"code": "250"}}
                ],
              	"priceWaterfallBasisQuantityNumber": [
                	{"data": 1, "expressedIn": {"code": "cnt"}}
                ],
                "priceWaterfalls": [
                    {
                        "bracketUnit": {"code": "ctn"},
                        "brackets": [
                            {"min": 1},
                            {"min": 10},
                        ],
                        "levels": [{
                            "type": {"code": "price"},
                            "items": [{
                                "description": "Gross price",
                                "type": {"code": "grossPrice"},
                                "unit": {"code": "$"},
                                "values": [
                                    {"value": ""},
                                    {"value": ""},
                                ],
                            }],
                        }],
                    },
                ],
            },
            "name": "Tariff 2019",
            "status": "DRAFT",
            "targetOrganization": {
                "gln": "{your recipient GLN}",
            },
            # "uuid": "..."  # Set the uuid to update the tariff defined by the uuid
        }
    ]
}
response = requests.post(
    "https://apis.supplierxm.salsify.com/public/v1/tariffs",
    data=json.dumps(tariff),
    headers=headers,
).json()

# The resonse contains the created tariffs in the same order as the request
# payload
tariff_uuid = response['data'][0]['uuid']

As represented on the platform:

1814

We will now link 2 products to this tariff:

  • GTIN_1: this one is not yet in your catalog and hence will be created empty
  • GTIN_2: this one is in your catalog. It has one logistical hierarchy with a pallet defined by GTIN_2_PALLET

You can update a tariff’s associated products by using the https://apis.supplierxm.salsify.com/public/v1/tariffs/{uuid}/products API. See Tariffs products upsert for more details.

products = {
    'data': [{
        'gtin': 'GTIN_1',  # This product will be created
        'suppliedId': '0123456',  # Common between all the tariffs to which the product is linked
        'data': {  # Tariff-specific data for the product
            'contractNumber': '1234-123456-12',
            'priceWaterfalls': [{
                'product': {'gtin': 'GTIN_1'},
                'bracketUnit': {'code': 'ctn'},
                'brackets': [
                    {'min': 1},
                    {'min': 10},
                ],
                'levels': [{
                    'type': {'code': 'price'},
                    'items': [{
                        'description': 'Gross price',
                        'type': {'code': 'grossPrice'},
                        'unit': {'code': '$'},
                        'values': [
                            {'value': '10'},
                            {'value': '9'},
                        ],
                    }],
                }],
            }],
        },
    }, {
        'gtin': 'GTIN_2',  # This product will be linked to the tariff
        'suppliedId': '0123456',
        'data': {
            'contractNumber': '1234-123456-12',
            'hierarchyProduct': {
                'gtin': 'GTIN_2_PALLET',
            },
            'priceWaterfalls': [{
                'product': {'gtin': 'GTIN_2'},
                'bracketUnit': {'code': 'ctn'},
                'brackets': [
                    {'min': 1},
                    {'min': 10},
                ],
                'levels': [{
                    'type': {'code': 'price'},
                    'items': [{
                        'description': 'Gross price',
                        'type': {'code': 'grossPrice'},
                        'unit': {'code': '$'},
                        'values': [
                            {'value': '12'},
                            {'value': '10'},
                        ],
                    }],
                }],
            }],
        },
    }]
}
requests.post(
    "https://apis.supplierxm.salsify.com/public/v1/tariffs/%s/products" % tariff_uuid,
    data=json.dumps(products),
    headers=headers,
).json()

The first product will be represented on the platform as:

1272

Let's say now that the target country filled when creating the tariff is not correct. We want to update it:

# Let's now update the target country:
tariff['data'][0]['uuid'] = tariff_uuid
tariff['data'][0]['data']['targetCountryList'][0]['targetCountryCode']['code'] = '250'
response = requests.post(
    "https://apis.supplierxm.salsify.com/public/v1/tariffs",
    data=json.dumps(tariff),
    headers=headers,
).json()

👍

Congratulations

Check out your tariffs on SupplierXM, and you should see your newly created and updated tariff with 2 products linked to it.

Once everything is in order, and you no longer need to edit or add any products, you have to publish the tariff in order to make it available to the retailer. You can follow the documentation on Publish Tariffs.

API References

Tariff update
Tariff products upsert


What’s Next