Skip to content
B2B GroupPartner API

Sandbox

The sandbox is a test mode of the same API, on its own host:

https://api-sandbox.b2bgroup.dk

It runs the same code as production, with the same routes, limits and errors. What differs:

  • Separate clients. A sandbox client only works on the sandbox host, and a production client only on the production host. Using the wrong host answers 401 invalid_client on the token route, with a message that names the right host, and 401 invalid_token on the other routes.
  • Separate data. Sandbox codes, events and orders are invisible in production and the other way round. A production code looked up in the sandbox answers 404 code_not_found.
  • Nothing real happens. Sandbox codes can only be redeemed in a sandbox shop. Sandbox orders are never invoiced or shipped.
  • Automatic cleanup. The automatic cleanup at 03:00 Danish time removes sandbox codes, webhook events, deliveries and orders older than 24 hours. Your clients, secrets, developers and webhook endpoints are kept.
  • Simulation routes. Two extra routes let you play the member and the warehouse.

Simulate a redemption

POST /v1/sandbox/codes/{code}/redeem - scope codes:manage. Redeems the code the way the shop would: the code becomes used, a sandbox order is created, and code.redeemed is sent to your webhook endpoints.

{
  "selection": [ { "sku": "BBP-1234", "quantity": 1 } ],
  "delivery": { "name": "Test Member", "address": "Test Street 1", "zip": "6760", "city": "Ribe",
                "email": "member@example.com", "phone": "+45 12 34 56 78", "country": "DK" }
}

The answer is the code object (see Codes) with status used and a redemption holding orderId.

  • sku must be a product in your sandbox shop; an unknown SKU answers 400 validation_error. Your contact at B2B Group tells you which SKUs your sandbox shop has.
  • delivery needs name, address, zip and city; email, phone and country are optional and come back in the code detail and in code.redeemed, as they will from the real shop.
  • The code rules of the real shop apply: a used code answers 409 code_already_used, an expired or deactivated code 400 code_expired or code_deactivated.
  • The tier rule of the real shop applies too. If the tier of the code is lower than the tier of a gift in selection, the answer is 400 insufficient_tier and the code stays unused. Issue the code with a higher tier to test that gift. See "Tiers" in Codes.
  • If no sandbox shop is set up for your account yet, the answer is 409 sandbox_shop_missing.

curl

curl -s https://api-sandbox.b2bgroup.dk/v1/sandbox/codes/ABC-7K3Q-M8ZP/redeem \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{ "selection": [ { "sku": "BBP-1234", "quantity": 1 } ],
        "delivery": { "name": "Test Member", "address": "Test Street 1", "zip": "6760", "city": "Ribe",
                      "email": "member@example.com", "phone": "+45 12 34 56 78", "country": "DK" } }'

C#

var response = await http.PostAsJsonAsync($"/v1/sandbox/codes/{Uri.EscapeDataString(code)}/redeem", new
{
    selection = new[] { new { sku = "BBP-1234", quantity = 1 } },
    delivery = new
    {
        name = "Test Member", address = "Test Street 1", zip = "6760", city = "Ribe",
        email = "member@example.com", phone = "+45 12 34 56 78", country = "DK",
    },
});
response.EnsureSuccessStatusCode();
var redeemed = await response.Content.ReadFromJsonAsync<JsonElement>();
var orderId = redeemed.GetProperty("redemption").GetProperty("orderId").GetInt32();

Node

const response = await fetch(`${baseUrl}/v1/sandbox/codes/${encodeURIComponent(code)}/redeem`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    selection: [{ sku: 'BBP-1234', quantity: 1 }],
    delivery: {
      name: 'Test Member', address: 'Test Street 1', zip: '6760', city: 'Ribe',
      email: 'member@example.com', phone: '+45 12 34 56 78', country: 'DK',
    },
  }),
});
const { redemption } = await response.json();
const orderId = redemption.orderId;

Python

response = session.post(f"{BASE_URL}/v1/sandbox/codes/{code}/redeem", json={
    "selection": [{"sku": "BBP-1234", "quantity": 1}],
    "delivery": {"name": "Test Member", "address": "Test Street 1", "zip": "6760", "city": "Ribe",
                 "email": "member@example.com", "phone": "+45 12 34 56 78", "country": "DK"},
})
response.raise_for_status()
order_id = response.json()["redemption"]["orderId"]

Simulate a shipment

POST /v1/sandbox/orders/{orderId}/ship - scope codes:manage. Ships the sandbox order: the code's redemption.shipment is filled in and code.shipped is sent.

{ "carrier": "GLS", "trackingNumber": "TEST-000123" }

The answer is the code object with the shipment. trackingNumber is required (400 validation_error without it). An order id that does not exist answers 404 not_found.

curl -s https://api-sandbox.b2bgroup.dk/v1/sandbox/orders/5511/ship \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{ "carrier": "GLS", "trackingNumber": "TEST-000123" }'

A complete test run

  1. Get a token on the sandbox host.
  2. Register a webhook endpoint that points at your test receiver.
  3. Issue a code with POST /v1/codes/issue.
  4. Redeem it with POST /v1/sandbox/codes/{code}/redeem and check that your receiver got code.redeemed with a valid signature.
  5. Ship it with POST /v1/sandbox/orders/{orderId}/ship and check code.shipped.
  6. Issue another code, deactivate it with POST /v1/codes/{code}/deactivate, and check code.deactivated.
  7. Run your daily pull with GET /v1/codes?updatedSince=... and check that all three codes are there with the right status.

The simulation routes do not exist on the production host; there they answer 404 not_found.