Skip to content

Quickstart

In 15 minutes you will send an event to the test environment and see how it changed a user’s progress.

  1. Get your test mode keys. For now we connect clients by hand: ask your A-App manager, and they will give you three values:

    What Looks like Used for
    API key aapp_test_… the Authorization header of every request
    Event signing secret whsec_… signing POST /v1/events
    Webhook secret whsec_… verifying the signature of our webhooks

    Keep them on your server only. They never go to a browser, a mobile app or a repository.

  2. Sign and send an event. Every event is signed with the Standard Webhooks scheme: HMAC-SHA256 of the string {webhook-id}.{webhook-timestamp}.{body}. The HMAC key is the part of the secret after whsec_, decoded from base64. Sign exactly the bytes you send as the body.

    // app/lib/aapp.ts: only on the server, never in a client component
    import { createHmac } from 'node:crypto';
    const API = 'https://test-api.dnk.az';
    export async function sendEvent(event: Record<string, unknown> & { event_id: string }) {
    const body = JSON.stringify(event);
    const timestamp = Math.floor(Date.now() / 1000).toString();
    const key = Buffer.from(process.env.AAPP_SIGNING_SECRET!.slice('whsec_'.length), 'base64');
    const signature = createHmac('sha256', key)
    .update(`${event.event_id}.${timestamp}.${body}`)
    .digest('base64');
    const res = await fetch(`${API}/v1/events`, {
    method: 'POST',
    headers: {
    Authorization: `Bearer ${process.env.AAPP_API_KEY}`,
    'Content-Type': 'application/json',
    'webhook-id': event.event_id,
    'webhook-timestamp': timestamp,
    'webhook-signature': `v1,${signature}`,
    },
    body,
    signal: AbortSignal.timeout(10_000),
    });
    return { status: res.status, body: await res.json() };
    }
    await sendEvent({
    event_id: 'evt_90114',
    type: 'order.paid',
    user_ref: '4f9a',
    order_id: 'ord_78123',
    occurred_at: new Date().toISOString(),
    amount: 25.0,
    currency: 'AZN',
    items: [{ sku: 'game-123', category: 'rpg', price: 25.0, qty: 1 }],
    });

    A 202 response means the event is accepted. Repeating the request with the same event_id and body is safe: the duplicate changes nothing.

  3. Check what happened to the event. We count it in the background, usually within seconds.

    Окно терминала
    curl -sS "$API/v1/events/evt_90114" -H "Authorization: Bearer $AAPP_API_KEY"

    The status field shows whether the event was counted: accepted means it is still queued, processed means it was counted and changes lists what changed, ignored means it counted nowhere and reason explains why, for example the event type is not described in your dictionary yet.

  4. Get the user’s status.

    Окно терминала
    curl -sS "$API/v1/users/4f9a/status" -H "Authorization: Bearer $AAPP_API_KEY"

    The response holds the user’s group (participant or control), badges, progress in each scenario and rewards. A new user without events also gets 200: the available scenarios with status not_started.

  5. Receive a webhook. When a reward becomes available, we send reward.available to your URL. How to receive it and verify the signature is in the Receiving webhooks guide.