Skip to navigation

Your first API call

Sign in, price a basket, and read the discount the till would have applied.
View as Markdown

The quickest way to see 52ViKING actually doing something is to price a basket. It is one call, it is read-only, and the response shows the promotion engine at work.

You will need a chain number, a store number, and credentials from your FiftyTwo consultant.

1

Get an access token

export FT_TOKEN=$(curl -s -X POST https://auth.fiftytwo.com/v1/user \
-H "Content-Type: application/json" \
-d '{"username":"'"$FT_USER"'","password":"'"$FT_PASS"'"}' \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])')
echo "${FT_TOKEN:0:24}..."

If that prints a truncated JWT, you are authenticated. If it prints nothing, re-read Authentication.

2

Price a basket

CalculateBasket takes the chain and store in the path, because promotions are store-specific.

curl -X POST \
"https://api.fiftytwo.com/basket/basket/calculatebasket/1/0142" \
-H "Authorization: Bearer $FT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"lines": [
{ "ean": "5701234000019", "quantity": 1 },
{ "ean": "5701234000217", "quantity": 1 }
]
}'

Basket API accepts either XML or JSON for both request and response. Set Content-Type and Accept to whichever you prefer. Check the request schema for the exact line-item field names your chain’s configuration expects.

3

Read the discount lines

The response is line-orientated: each line in your request stays its own line in the receipt. Lines are never collapsed or expanded, so a quantity of three is one line, not three.

Discounts arrive as their own lines, referencing the rule that produced them. That reference is the discount group or campaign ID you can look up through Master Data, which is how you explain a price back to a customer.

4

Compare against a till

The point of Basket API is that it uses the same logic as a physical till. Ring the same basket up on a real POS and the totals should match to the øre. If they do not, the usual cause is the store number: promotions differ per store.

What to build next

Concepts worth ten minutes

These explain the model the API field names assume: