تخطَّ إلى المحتوى
نسخة معاينة للمطورين: قد تتغير الواجهة قبل الإطلاق العام. اطلب الانضمام

Quickstart

هذا المحتوى غير متوفر بلغتك بعد.

This guide uses the sandbox, which has test merchants and can create test orders. You need your sandbox token URL, client ID and client secret from the Loops Partners portal (Applications). Request access if you don’t have them yet.

  1. Get an access token

    Exchange your client ID and secret for an access token. Tokens last 15 minutes; request a new one when it expires.

    Terminal window
    curl -X POST $LOOPS_TOKEN_URL \
    -d grant_type=client_credentials \
    -d client_id=$LOOPS_CLIENT_ID \
    -d client_secret=$LOOPS_CLIENT_SECRET
    { "access_token": "eyJhbGciOi…", "expires_in": 900, "token_type": "Bearer" }
  2. Check a merchant connection

    Every request names the merchant in the Loops-Merchant-Id header. Your sandbox comes with a test merchant.

    Terminal window
    curl https://sandbox.partners.loops.sa/v1/connection \
    -H "Authorization: Bearer $TOKEN" \
    -H "Loops-Merchant-Id: mer_7Hq2Lw8Z"

    The response shows the scopes and locations that merchant granted you.

  3. List the merchant’s locations

    Terminal window
    curl https://sandbox.partners.loops.sa/v1/locations \
    -H "Authorization: Bearer $TOKEN" \
    -H "Loops-Merchant-Id: mer_7Hq2Lw8Z"
  4. Create a test order (sandbox only)

    Terminal window
    curl -X POST https://sandbox.partners.loops.sa/v1/sandbox/orders \
    -H "Authorization: Bearer $TOKEN" \
    -H "Loops-Merchant-Id: mer_7Hq2Lw8Z" \
    -H "Content-Type: application/json" \
    -d '{ "location_id": "loc_2Xf9K" }'
  5. Read orders

    Terminal window
    curl "https://sandbox.partners.loops.sa/v1/orders?location_id=loc_2Xf9K&limit=10" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Loops-Merchant-Id: mer_7Hq2Lw8Z"
  6. Receive webhooks

    Add an endpoint in the Loops Partners portal and subscribe to order.*. Verify each request’s signature before trusting it:

    import { Webhook } from "standardwebhooks";
    const wh = new Webhook(process.env.LOOPS_WEBHOOK_SECRET);
    app.post("/loops/webhooks", express.raw({ type: "application/json" }), (req, res) => {
    const event = wh.verify(req.body, req.headers); // throws if invalid
    queue.push(event); // acknowledge fast, process later
    res.sendStatus(200);
    });