# Deliver from your own server

For accounts, codes and access your own system creates on demand. When an order is paid, anyshop sends your server a signed request with the order, your server answers with what the buyer gets, and anyshop shows it on the buyer's order page and emails it, in your store's name.

- A product of type Dynamic
- Standard Webhooks signature
- Retries for 3 days

## Set up the product

1. In the dashboard, open **Products** and create a product. Under **Deliverables**, choose **Dynamic, from your server**.
2. In **Your server's address**, give the https address anyshop calls, such as `https://example.com/anyshop/deliver`. It must be public: anyshop never calls private networks and never follows redirects.
3. Copy the **Signing secret** shown under it, `whsec_...`, into your server's settings. It is also under Developers, Docs. Owners and admins can reveal it, and each reveal is recorded in your security log.
4. Optionally, add a **Note for the buyer**, shown with what your server returns.

With the API, create the product with `POST /v1/products`, `"type": "dynamic"` and `dynamic_endpoint_url`, and a key with `products:write`.

There is one signing secret per store, shown under Developers, Docs. Every sale is signed with it, and so is **Send a sample request** in the product editor, marked `"test": true`.

## The request

After each payment, anyshop sends one `POST` for each item of the order, with a JSON body:

order.fulfill:

```json
{
  "type": "order.fulfill",
  "timestamp": "2026-11-11T14:21:07.000Z",
  "data": {
    "order": { "id": "ord_01m3rt5x2c7q9f0a4d6k8h1n3p", "number": 1042, "livemode": true },
    "item": {
      "id": "oi_01m3rt5x4e9s1h2c6d8f0g2j4k",
      "product": { "id": "prod_01m3rr5kmbeb2s18x1kpntjxqb", "name": "Orbit Studio Membership" },
      "variant": { "id": "var_01m3rs9d2f4k6m8p0r2t4v6x8z", "name": "Yearly" },
      "quantity": 1,
      "answers": [
        {
          "question_id": "pq_01m3rrb2c4e6g8j0m2p4r6t8w0",
          "question": "The account username to activate",
          "kind": "short_text",
          "answer": "ada_l"
        }
      ]
    },
    "buyer": { "email": "ada@example.com" }
  }
}
```

An item with a quantity of 2 or more is one request: your answer is what the buyer gets for all of them. A sample request from the product editor adds `"test": true`, with `ord_test`, `oi_test`, order number 0 and `test-buyer@example.com`.

`item.answers` holds the buyer's answers to the product's questions for the buyer, set in the product editor under Checkout (up to 3, such as the username of the account to activate): each with the question's ID, the question as the buyer read it, its kind (`short_text`, `email` or `choice`) and the answer, in the questions' order. It is empty when the product asks nothing, and an optional question the buyer left empty is not listed. An item of a bundle carries the bundle's answers: a bundle asks its own questions, never its products'. They are inside the signed body, like everything else in it, and the order's timeline says the request went with them. A sample request answers each question with `test` (a choice with its first option). anyshop keeps the answers encrypted with the order and never puts them in an email: do not echo them in your answer's `text`, which the delivery email shows.

| Header | What it holds |
| --- | --- |
| `content-type` | `application/json` |
| `user-agent` | `anyshop-delivery/1` |
| `webhook-id` | The delivery's ID (`fjob_...`), the same on every retry: create the item once per ID |
| `webhook-timestamp` | When this attempt was signed, in Unix seconds |
| `webhook-signature` | `v1,` and the signature |

## Verify and answer

Requests are signed as [Standard Webhooks](https://www.standardwebhooks.com), exactly like webhook deliveries (see [React to orders](https://docs.anyshop.io/guides/webhooks.md#verify-signatures)): its libraries verify them with your signing secret. Verify the body exactly as it arrived, before any JSON parsing, and refuse timestamps more than 5 minutes away from your clock.

Unlike a webhook, the answer is the delivery: do the work, then answer within 15 seconds. Because a retry can come after your server created the item but before its answer got through, keep what you created under the `webhook-id`, and answer a retry with the same item.

Node (server.js):

```js
import express from "express";
import { Webhook } from "standardwebhooks";

const webhook = new Webhook(process.env.ANYSHOP_DELIVERY_SECRET); // whsec_...
const app = express();

app.post("/anyshop/deliver", express.raw({ type: "application/json" }), async (req, res) => {
  let request;
  try {
    request = webhook.verify(req.body, req.headers);
  } catch {
    return res.sendStatus(400);
  }
  if (request.test) return res.json({ text: "Sample request: nothing was created." });
  // Once per webhook-id: a retry gets the item made the first time.
  const item = await deliveries.findOrCreate(req.headers["webhook-id"], () =>
    createMembership(request.data.buyer.email, request.data.item),
  );
  res.json({ text: `Your access code: ${item.code}`, url: "https://example.com/welcome" });
});
```

Python (server.py):

```python
import os
from flask import Flask, jsonify, request
from standardwebhooks.webhooks import Webhook

webhook = Webhook(os.environ["ANYSHOP_DELIVERY_SECRET"])  # whsec_...
app = Flask(__name__)

@app.post("/anyshop/deliver")
def deliver():
    try:
        order = webhook.verify(request.get_data(), dict(request.headers))
    except Exception:
        return "", 400
    if order.get("test"):
        return jsonify(text="Sample request: nothing was created.")
    # Once per webhook-id: a retry gets the item made the first time.
    item = deliveries.find_or_create(
        request.headers["webhook-id"],
        lambda: create_membership(order["data"]["buyer"]["email"], order["data"]["item"]),
    )
    return jsonify(text=f"Your access code: {item.code}", url="https://example.com/welcome")
```

> **No library for your language?** Compute HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{body}` with the secret's bytes (the part after `whsec_`, base64 decoded), base64 encode it, and compare it in constant time with the signature after `v1,`.

## What your server answers

A `2xx` status with a JSON object holding `text`, `url`, or both:

| Field |  |
| --- | --- |
| `text` | What the buyer reads: a code, an account name, instructions. Up to 10,000 characters; longer is cut. |
| `url` | An https link for the buyer, such as a page to sign in or redeem. Anything but https is dropped. |

Your answer:

```json
{ "text": "Your access code: MEMBER-4417", "url": "https://example.com/welcome" }
```

The buyer sees it on their order page and gets it by email, with your note. What your server returned is stored encrypted. Once every item of the order is delivered, your webhooks get `order.fulfilled`.

Anything else is a failed attempt: another status, no answer within 15 seconds, no connection, a body over 64 KB, or JSON with neither a `text` nor an https `url`.

## Retries

A failed attempt is tried again 5 seconds later, then after 5 minutes, 30 minutes, 2 hours, 5 hours, 10 hours, 10 hours, 24 hours and 24 hours: 10 attempts over about 3 days, each wait up to 20% shorter or longer at random. Every attempt has the same `webhook-id` and a fresh timestamp and signature.

- Meanwhile, the buyer's order page says their item is arriving shortly.
- After the last attempt, the item is marked failed, and you get an email to deliver it yourself.
- An order refunded before its item arrived stops being retried.

## Send a sample request

In the product editor, once the product is saved, **Send a sample request** sends your server one signed request as a sale would, marked `"test": true`, and shows what came back: what a buyer would get, or why it failed (the status your server answered, an answer that is not the JSON above, or that anyshop could not reach it). Nothing is stored and no buyer is involved, so your server should not hand out a real item for it.

## Try it, then sell

Send a sample request from the product editor while you build. Once anyshop has approved your store, buy the product once with your own email to see a real delivery, and refund it from the order page.

[Next: react to events](https://docs.anyshop.io/guides/webhooks.md)
