> ## Documentation Index
> Fetch the complete documentation index at: https://developers.scoutworks.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Writing data

> Every change follows the same three rules: Idempotency-Key on a create, If-Match on a change, and one result per item in a bulk write.

Every endpoint that changes data works the same way. A key that can write follows three rules, whichever area it writes to.

## Retry a create safely: `Idempotency-Key`

A request can time out after Scoutworks has made the record. If you send it again, you could make a second one. To stop that, send an **`Idempotency-Key`** header with every `POST`: any printable text up to 255 characters, unique to the record you are making. A UUID is a good choice.

```bash theme={null}
curl -X POST https://api.scoutworks.app/api/v1/tasks \
  -H "Authorization: Bearer $SCOUTWORKS_KEY" \
  -H "Idempotency-Key: 2c0c6c1e-6b8f-4d4e-9a57-2b4d0f9b1c3a" \
  -H "Content-Type: application/json" \
  -d '{"boardId": "PASTE_BOARD_ID", "title": "Apply to the community fund"}'
```

For 24 hours, Scoutworks remembers the key:

| You send | The answer |
| - | - |
| The same key and the same body | `200` with the record the first request made, and the header `Idempotent-Replayed: true`. Nothing new is made. |
| The same key and a different body | `400` `invalid_request`. Use a new key for a new record. |
| The same key while the first request is still running | `409` `conflict`. Wait a moment, then send it again. |

Each key keeps its own list, so two of your keys can use the same `Idempotency-Key` without clashing. Most creates accept the header and recommend it. A create that must never run twice, such as `POST /transactions`, requires it and answers `400` without it.

## Do not overwrite a newer change: `If-Match`

Every record you read with a single-record `GET`, and every record a write returns, comes with an **`ETag`** header. The tag changes whenever anything in the record changes.

To change a record only if nobody else has changed it since you read it, send that tag back as **`If-Match`** on the `PATCH`, `PUT` or `DELETE`:

```bash theme={null}
curl -X PATCH https://api.scoutworks.app/api/v1/tasks/PASTE_TASK_ID \
  -H "Authorization: Bearer $SCOUTWORKS_KEY" \
  -H 'If-Match: "9f2c4e1b7a3d5c6e8f0a1b2c3d4e5f60"' \
  -H "Content-Type: application/json" \
  -d '{"title": "Apply to the community fund by Friday"}'
```

If the record has changed, the API answers **`412`** with the code `stale_write`, and changes nothing. The `412` carries the record's current `ETag`. Read the record again, decide what to do with the new values, and send the change with that tag.

* Send the tag exactly as you received it, quotes included. `If-Match: *` matches any version.
* `If-Match` is optional. Without it, the last write wins. We recommend it for anything a person might also edit in Scoutworks.
* The tag describes the record as your key sees it. A key with more scopes sees more fields, so it gets a different tag for the same record.
* The tag covers everything in the record, totals included. A budget's `spent` and a fund's `remaining` change when someone records a transaction against them, so the tag changes too, even if nobody edited the budget or fund. On a busy budget, expect the occasional `412`: retry with the tag it carries.

`PATCH /transactions/{transactionId}` also takes the `updatedAt` you last read, in the body, and answers `412` the same way when it is stale.

## Write many records at once: bulk writes

Endpoints that write many records in one request all work the same way: `PUT /events/{eventId}/attendance` (one register), `POST /attendance/bulk` (marks across registers), `POST /badge-requirements/bulk` (badge sign-offs) and `POST /badge-awards/bulk` (badge awards). They take a body of `{ "items": [...] }`, with 1 to 100 items, and answer `200` with one result for each item, in the order you sent them:

```json theme={null}
{
  "data": [
    { "index": 0, "status": "created", "id": "…" },
    { "index": 1, "status": "unchanged", "id": "…" },
    { "index": 2, "status": "error", "error": { "code": "invalid_request", "message": "…" } }
  ],
  "summary": { "created": 1, "updated": 0, "unchanged": 1, "failed": 1 }
}
```

* An item that is not valid, or that is refused, does not stop the others. Its result has `status: "error"` and says why, and none of its changes are saved.
* A request with no items, or more than 100, is refused as a whole with `400`.
* Each item is matched on what it is about (a member and a meeting, say), so sending the same items again is safe: unchanged items answer `unchanged`.
* A bulk request counts as **one** change against the limit of 30 changes a minute. See [Rate limits](https://developers.scoutworks.app/guides/rate-limits.md).
* A bulk `POST` also takes an `Idempotency-Key`. You do not need one to retry safely, but with one, a second copy of the request sent while the first is still running answers `409` instead of running too. A replay with the same key and body runs the items again and answers with `Idempotent-Replayed: true`; each item then answers as it stands, which is `unchanged` for an item the first request wrote.
* `PUT /events/{eventId}/attendance` takes `If-Match` with the register’s `ETag` from `GET /events/{eventId}/attendance`, and answers with the register’s new `ETag`.

Try a write on one record first: send one item, check the result in Scoutworks, then send the rest. The [sandbox key](https://developers.scoutworks.app/guides/sandbox.md) is read-only, so use your own key with the `write` scope, on a young person whose record you can put back.

## Try a write safely

There is no practice mode, and the public [sandbox key](https://developers.scoutworks.app/guides/sandbox.md) is read only. So test a write on your own group, with **your own key**, on a record you made for the purpose:

1. **Make a test record with the write itself.** Add a test member called "Test Member", a draft event, or a waiting-list application for a made-up child. A draft event is the safest: families hear of an event only when a leader publishes it.
2. **Check it in Scoutworks.** Open the record and see that every field landed where you meant.
3. **Undo it in Scoutworks.** Archive the test member, delete the draft event or the application, or delete the test transaction. The API never deletes a member, so this step is in the app.
4. **Then run it for real.** Start with one real record, check it, then the rest.

Writes through the API **never email or notify a family** unless the request sends `"notify": true`. Leave it out while you test.

Each recipe shows one write in full: [curl](https://developers.scoutworks.app/recipes/curl.md#write-data), [Python](https://developers.scoutworks.app/recipes/python.md#write-data), [JavaScript](https://developers.scoutworks.app/recipes/javascript.md#write-data), [PowerShell](https://developers.scoutworks.app/recipes/powershell.md#write-data) and [n8n](https://developers.scoutworks.app/recipes/n8n.md#write-data).

## Who made the change

A change made with a key is recorded as made by the admin who created the key, and Scoutworks marks the record with the key's name, so people can see a script did it. A write never emails or notifies parents unless the request asks it to. `POST /badge-requirements/bulk` takes `notify: true` to send the one notice the app sends for a sign-off, the Young Leader’s own; without it, nobody is told. A register mark or a badge award sends nothing either way, as in the app.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.