# Writing data

> Create, change and delete rows in the Fledge API, with ETags, and call actions such as price updates.

Writing needs one of the entity set's **write licenses** (see [Authentication](https://docs.fledge.nl/en/api/authentication)). The [reference](https://docs.fledge.nl/en/api/reference) shows per entity set which operations it has.

| Operation | Request | Success |
| --- | --- | --- |
| Create | `POST /<EntitySet>` with the row as JSON | `201` and the new row |
| Change | `PATCH /<EntitySet>(<key>)` with only the fields that change, and `If-Match` | `200` and the saved row |
| Delete | `DELETE /<EntitySet>(<key>)` with `If-Match` | `204` |

## Create

Post to the entity set at the root, with `administration_id` in the body:

```http
POST /SalesOrderHeaders
Content-Type: application/json

{ "administration_id": 1, "relation_id": 1002, "order_date": "2026-12-02" }
```

Create related rows with their own requests: one request can't create a header and its lines together.

## Change and delete: ETags

Every row has an `@odata.etag`. A `PATCH` or `DELETE` must send the row's current ETag in `If-Match`, so it doesn't overwrite a change someone else made in the meantime.

```http
PATCH /SalesOrderHeaders(administration_id=1,sales_order_header_id='VK252846')
If-Match: <@odata.etag of the row>
Content-Type: application/json

{ "your_reference": "PO-4711" }
```

| Answer | Meaning | What to do |
| --- | --- | --- |
| `412` `ETAG_MISSING` | No `If-Match` | Read the row first, send its `@odata.etag` |
| `412` `ETAG_MISMATCH` | The row changed since you read it | Read it again, check, and try again |
| `409` | Two saves at the same time | Try again |
| `403` `PATCHING_PRIMARY_KEYS_FORBIDDEN` | A key field in the body | Leave key fields out of a `PATCH` |
| `422` | The row doesn't pass Fledge's checks | Read the message; fix the data |

A successful `PATCH` returns the saved row with its new ETag: use that one for the next change. Don't send `Prefer: return=representation`.

## Actions

Actions do work that is more than one row, such as updating prices or delivering an order. Post to the action, on the entity set or on one row, with its parameters as the JSON body:

```http
POST /Articles/updatePrices
Content-Type: application/json

{
  "price_type": "…",
  "change_type": "…",
  "value": 5,
  "Articles": [ { "administration_id": 1, "article_id": "10045" } ]
}
```

The reference lists the actions per entity set, with their parameters.

## Write options

Some writes take an option in the body, as a property that starts with `@nl.fledge.`, for example:

```json
{ "…": "…", "@nl.fledge.ignore_credit_limit_exceedance": true }
```

An unknown option gives an error.

## Read-only entity sets

A few entity sets can't be written through the API: they answer `501`. The reference shows only the operations each set has.

---

Source: https://docs.fledge.nl/en/api/writing-data
