packerooDevelopers Deutsch

Your first call in five minutes

Ask the sandbox for a code for a table device and read GET /device with its token. With Python, JavaScript, C#, PHP, Go, Java, curl and for the ESP32.

You need a terminal, and the Arduino IDE for the ESP32. You do not need a packeroo account in the sandbox: a device asks for its code without signing in and confirms it there itself. The language you pick here holds for every example on this page, in the guide and in the reference. PowerShell, Ruby, Kotlin, Swift, Dart and Rust are in the reference.

1. Ask for a code

Send POST /device-pairings to the sandbox. Two headers are required: User-Agent names your device with product and firmware, and Idempotency-Key is a UUID or ULID you make new for this request.

import json, urllib.request, uuid

request = urllib.request.Request(
    "https://api.qm.packeroo.com/api/v1/device-pairings",
    method="POST",
    data=json.dumps({"model": "Kickertisch-Beispiel", "firmware": "1.0"}).encode(),
    headers={
        "User-Agent": "Kickertisch-Beispiel/1.0",
        "Idempotency-Key": str(uuid.uuid4()),
        "Content-Type": "application/json",
        "Accept-Language": "en",
    },
)
with urllib.request.urlopen(request) as response:
    print(json.load(response)["data"])

The answer comes with 201 Created:

{
  "data": {
    "code": "K7F4QX",
    "expires_at": "2026-11-22T14:15:00Z",
    "token": "pkd_test_7Hq2xV9pLm3RtY6wQz8NbC4kDf1Gs5Je0aB3cD"
  }
}

You see the token only this once. Put it into an environment variable in the same terminal; the examples of the next steps read it from there:

export PACKEROO_TOKEN='pkd_test_…'   # your token from the answer here
# PowerShell: $env:PACKEROO_TOKEN = 'pkd_test_…'

On the ESP32 the sketch keeps it in the variable token.

2. Ask with the token

Ask GET /device with the token. Until someone has entered the code, the API answers 401 with the code unauthenticated: the token counts only once the code belongs to a table. With a wrong token, or a pkd_test_ token against the live API, the answer looks the same. Step 3 shows whether your token is right.

import json, os, urllib.error, urllib.request

request = urllib.request.Request(
    "https://api.qm.packeroo.com/api/v1/device",
    headers={
        "User-Agent": "Kickertisch-Beispiel/1.0",
        "Authorization": "Bearer " + os.environ["PACKEROO_TOKEN"],
    },
)
try:
    with urllib.request.urlopen(request) as response:
        print(response.status, json.load(response)["data"])
except urllib.error.HTTPError as error:
    print(error.code, error.read().decode())

3. Have the code entered

Live, someone enters the code in the app, under Profile › Organization › Tables, then "Pair a device" at the table. In the sandbox no person is needed: your device confirms its code itself with POST /sandbox/device-pairings/confirm and the same token. It gets a test table of its own. If this answers 401, no code waits for the token: it is wrong, or the code ran out after 10 minutes. Then start again at step 1.

import json, os, urllib.error, urllib.request, uuid

request = urllib.request.Request(
    "https://api.qm.packeroo.com/api/v1/sandbox/device-pairings/confirm",
    method="POST",
    headers={
        "User-Agent": "Kickertisch-Beispiel/1.0",
        "Idempotency-Key": str(uuid.uuid4()),
        "Authorization": "Bearer " + os.environ["PACKEROO_TOKEN"],
    },
)
try:
    with urllib.request.urlopen(request) as response:
        print(response.status, json.load(response)["data"])
except urllib.error.HTTPError as error:
    print(error.code, error.read().decode())

The answer is the device already, as GET /device shows it. This operation exists in the sandbox only; live it answers 404, once User-Agent and Idempotency-Key are checked. The sandbox keeps the latest 100 test tables; the oldest is unpaired with its device when a new one comes.

Your device is paired now. From here on GET /device from step 2 answers 200:

{
  "data": {
    "id": "01JD7Q3V9TQ6Z8K2M4N5P6R7S8",
    "name": "Kickertisch Halle",
    "table": { "id": "01JD7Q2B1C3D4E5F6G7H8J9K0M", "name": "Tisch 2" },
    "location": { "id": "01JD7Q1A2B3C4D5E6F7G8H9J0K", "name": "Büro Freiburg", "time_zone": "Europe/Berlin" },
    "organization": { "id": "01JD7Q0Z9Y8X7W6V5T4S3R2Q1P", "name": "Beispiel AG" },
    "scopes": ["leagues:read", "standings:read", "matches:read", "matches:write", "matches:live"]
  }
}

The values above are an example. scopes names what the token may do later; the operations for it are planned.

Next

This page as Markdown