# Archive Stripe, GitHub and Shopify webhooks in your own bucket

Webhook senders retry for a while and then give up, and they keep their delivery history for days, not years. An endpoint that writes every delivery to a bucket you own keeps the full history to audit, replay or query, next to the endpoint your app already handles.

:::note
We sent a pretty-printed Stripe event and compact GitHub and Shopify bodies, each shaped like the sender's documented payload, to a local Send2Bucket node writing to S3-compatible storage, with the key in the URL, and ran the check request and the DuckDB queries (DuckDB 2.0) on the objects it wrote. The Stripe, GitHub and Shopify settings follow their docs, linked in each section, and were not run against those services.
:::

## How it works

```text
Stripe, GitHub, Shopify ──one JSON object per delivery──▶ /v1/events/json?api-key=<key> ──▶ your stream's destination
```

- Each delivery becomes one line with `signal` `log`, the body kept as the sender sent it. [Delivery format](../delivery-format.md#log-drains) describes the line.
- A `200` means the delivery is stored durably and will be delivered at least once, so the sender marks it delivered. See [Delivery semantics](../delivery-semantics.md).
- Senders cannot set an `Authorization` header, so the API key goes in the URL, and the key is what authenticates a delivery.
- Send2Bucket stores the body, not the headers. Signatures such as `Stripe-Signature`, `X-Hub-Signature-256` and `X-Shopify-Hmac-Sha256` are neither checked nor kept, and neither are GitHub's event name (`X-GitHub-Event`) or Shopify's topic (`X-Shopify-Topic`). Give each webhook its own stream when the body alone does not say what it is.

## 1. Create a stream and a key

Create an ingestion stream in the [dashboard](pathname:///app/), add a destination, and create an API key for this stream only. A key for one stream needs no `stream` parameter. The endpoint URL is:

```text
https://api.send2bucket.com/v1/events/json?api-key=<key>&stream=<stream_id>
```

Anyone with the URL can write to the stream, so treat it as a secret and rotate the key if it leaks. See [Drain keys and streams](../api-reference.md#drain-keys).

## 2. Add the webhook

### Stripe

In [Workbench](https://docs.stripe.com/workbench/event-destinations), open **Webhooks** and add a destination: pick the event types, choose **Webhook endpoint**, and paste the endpoint URL. Choose the **Snapshot** payload format, so each event carries the full object in `data.object`; a thin event carries only the object's ID.

In live mode, Stripe [retries a failed delivery](https://docs.stripe.com/webhooks) for up to 3 days.

### GitHub

In the repository's or organization's **Settings**, open **Webhooks** and add a webhook:

- Payload URL: the endpoint URL.
- Content type: `application/json`. The default, `application/x-www-form-urlencoded`, wraps the JSON in a `payload` form field, which Send2Bucket rejects with a `400`.
- Secret: optional; Send2Bucket does not check it.
- Events: the ones you want to keep.

See [Creating webhooks](https://docs.github.com/en/webhooks/using-webhooks/creating-webhooks).

### Shopify

In the Shopify admin, open **Settings**, then **Notifications**, then **Webhooks**, and create a webhook for each event you want to keep, with the **JSON** format and the endpoint URL. Apps subscribe through the Admin API instead; see [Shopify webhooks](https://shopify.dev/docs/apps/build/webhooks). Because the topic is a header, give each topic its own stream, or tell them apart by fields.

## 3. Check the endpoint

Before the sender delivers anything, check the URL with one event, pretty-printed as Stripe sends it. It stores one record, and the answer is a `200` with an empty body:

```bash
curl -i "https://api.send2bucket.com/v1/events/json?api-key=$S2B_API_KEY&stream=<stream_id>" \
  -H "Content-Type: application/json" \
  --data-binary $'{\n  "id": "evt_check",\n  "object": "event",\n  "type": "check"\n}'
```

A `401` means the key is wrong or revoked; a `403` or `400` names the stream problem; a `409` means the stream has no destination. The [API reference](../api-reference.md#log-drains) lists every error.

## 4. Query the deliveries

[DuckDB](../querying/duckdb.md) reads the objects in place. This view keeps the deliveries:

```sql
INSTALL httpfs; LOAD httpfs;
CREATE SECRET s2b (TYPE s3, PROVIDER credential_chain, REGION '<region>');

CREATE VIEW hooks AS
SELECT * FROM read_json(
  's3://<bucket>/<prefix>/s2b/stream=*/date=*/hour=*/*.ndjson.gz',
  format = 'newline_delimited',
  hive_partitioning = true,
  columns = {v: 'INTEGER', delivery_batch_id: 'VARCHAR', batch_id: 'VARCHAR',
             received_at: 'TIMESTAMPTZ', signal: 'VARCHAR',
             resource: 'JSON', scope: 'JSON', data: 'JSON'})
WHERE signal = 'log';
```

Stripe events per type and day. A retried event arrives again with the same `id`, so count distinct IDs:

```sql
SELECT to_timestamp((data->>'$.created')::BIGINT)::DATE AS day,
       data->>'$.type' AS type,
       count(DISTINCT data->>'$.id') AS events
FROM hooks
WHERE data->>'$.object' = 'event'
GROUP BY ALL
ORDER BY day DESC, events DESC;
```

Revenue from paid invoices, per currency, once per event. Stripe amounts are in the currency's smallest unit:

```sql
SELECT data->>'$.data.object.currency' AS currency,
       sum((data->>'$.data.object.amount_paid')::BIGINT) AS amount_paid
FROM (SELECT DISTINCT ON (data->>'$.id') data FROM hooks WHERE data->>'$.type' = 'invoice.paid')
GROUP BY ALL;
```

GitHub pushes per repository and branch, with their commit counts:

```sql
SELECT data->>'$.repository.full_name' AS repository,
       data->>'$.ref' AS ref,
       count(*) AS pushes,
       sum(json_array_length(data->'$.commits')) AS commits
FROM hooks
WHERE (data->'$.commits') IS NOT NULL
GROUP BY ALL
ORDER BY pushes DESC;
```

Shopify orders per day, from an orders stream:

```sql
SELECT (data->>'$.created_at')::TIMESTAMPTZ::DATE AS day,
       data->>'$.currency' AS currency,
       count(DISTINCT data->>'$.id') AS orders,
       sum((data->>'$.total_price')::DECIMAL(18, 2)) AS total
FROM hooks
WHERE stream = '<orders_stream_id>'
GROUP BY ALL
ORDER BY day DESC;
```

In an Iceberg or DuckLake table, the same line is in the `payload` column with `signal_type` `log`; see [Table columns](../delivery-format.md#table-columns).

## Notes

- **Duplicates**: senders retry until they get a `2xx`, and Send2Bucket stores each attempt. Stripe's `id` identifies an event; GitHub's and Shopify's delivery IDs are headers, so they are not kept.
- **Your app's endpoint**: add Send2Bucket as a second endpoint next to the one your app handles. Stripe, GitHub and Shopify each deliver to every endpoint that subscribes.
- **Billing**: each delivery's JSON as stored is the number billed, so pretty-printing whitespace is not counted. See [Plans and billing](../plans-and-billing.md).
- **Size**: a request can be up to 8 MiB decompressed. See [Limits](../api-reference.md#limits).
