Replay without issuing another code

A tool call may be retried after a timeout or by an assistant continuing a session. Keep a stable idempotency key for that offer request so a successful retry reuses the generated code. Compare the returned code; do not assume every response field is a frozen snapshot.

Response examples are illustrative unless labelled as a synthetic fixture. They preserve the API envelope but do not represent current availability, measured performance or checkout verification. Example codes cannot be redeemed; example links omit live attribution. Use the URLs returned by your real request.

What to inspect

idempotency_key
Use the same opaque key for the same shopper and offer session. Replace the documentation placeholder; do not share it across real shoppers.
code
The replay should return the same generated code while the underlying offer is available. A new key represents a new issuance request. The public demo changes its key at midnight UTC.
single_use
Replaying a single-use code does not reset its redemption state or make it reusable at checkout.
conditions + expires_at
Continue to respect the returned terms and expiry. A null expiry does not prove the code lasts forever.

Step 1 / POST /v1/merchants/codes

Request an offer with the merchant ID

Use the resolved merchant ID. Replace the example idempotency key with a stable, opaque key for this shopper and offer session. Keep it for retries. Terms, cashback and availability in a live response can differ from this illustration.

Set OPENSTOCK_API_KEY in your environment before running this request.

cURL request

curl -sS -X POST 'https://api.openstock.sh/v1/merchants/codes' \
  -H "Authorization: Bearer $OPENSTOCK_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"queries":[{"query_id":"brooklinen","merchant_id":"01g4s5d0h956te86ff90h6xts4","idempotency_key":"replace-with-your-shopper-session-key","limit":1}]}'

Request JSON

{
  "queries": [
    {
      "query_id": "brooklinen",
      "merchant_id": "01g4s5d0h956te86ff90h6xts4",
      "idempotency_key": "replace-with-your-shopper-session-key",
      "limit": 1
    }
  ]
}

Illustrative full response

{
  "results": [
    {
      "query_id": "brooklinen",
      "cashback": {
        "value_type": "percent",
        "value_amount": 3
      },
      "partnered": true,
      "activation_url": "https://api.openstock.sh/mr/01g4s5d0h956te86ff90h6xts4",
      "suppressed_code_count": 0,
      "items": [
        {
          "code": "EXAMPLE-NOT-REDEEMABLE",
          "source": "generated",
          "probability": 1,
          "single_use": true,
          "value_type": "percent",
          "value_amount": 15,
          "currency": null,
          "conditions": [],
          "redirect_url": "https://api.openstock.sh/mr/01g4s5d0h956te86ff90h6xts4?code=EXAMPLE-NOT-REDEEMABLE",
          "expires_at": null,
          "last_success": null,
          "description": "15% off",
          "apply_count": null,
          "success_count": null
        }
      ]
    }
  ]
}

Step 2 / POST /v1/merchants/codes

Repeat the exact request

Send the same body, including merchant_id and idempotency_key. The repeated illustrative response contains the same code. Asking the demo the same question again reuses the same key within a UTC day; compare both request keys in the API calls panel before assessing the generated code.

Set OPENSTOCK_API_KEY in your environment before running this request.

cURL request

curl -sS -X POST 'https://api.openstock.sh/v1/merchants/codes' \
  -H "Authorization: Bearer $OPENSTOCK_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"queries":[{"query_id":"brooklinen","merchant_id":"01g4s5d0h956te86ff90h6xts4","idempotency_key":"replace-with-your-shopper-session-key","limit":1}]}'

Request JSON

{
  "queries": [
    {
      "query_id": "brooklinen",
      "merchant_id": "01g4s5d0h956te86ff90h6xts4",
      "idempotency_key": "replace-with-your-shopper-session-key",
      "limit": 1
    }
  ]
}

Illustrative full response

{
  "results": [
    {
      "query_id": "brooklinen",
      "cashback": {
        "value_type": "percent",
        "value_amount": 3
      },
      "partnered": true,
      "activation_url": "https://api.openstock.sh/mr/01g4s5d0h956te86ff90h6xts4",
      "suppressed_code_count": 0,
      "items": [
        {
          "code": "EXAMPLE-NOT-REDEEMABLE",
          "source": "generated",
          "probability": 1,
          "single_use": true,
          "value_type": "percent",
          "value_amount": 15,
          "currency": null,
          "conditions": [],
          "redirect_url": "https://api.openstock.sh/mr/01g4s5d0h956te86ff90h6xts4?code=EXAMPLE-NOT-REDEEMABLE",
          "expires_at": null,
          "last_success": null,
          "description": "15% off",
          "apply_count": null,
          "success_count": null
        }
      ]
    }
  ]
}