# returnDocument Parameter

> Choose whether update by id and replace by id answer with the row as it was before the change or as it is after it, with ?returnDocument=before or after.

Source: https://docs.apimaker.dev/v1/docs/apis-all/query-params/returnDocument.html

`returnDocument` decides which version of the row an **update by id** or a **replace by id** sends back : the row **after** the change (the default) or the row **before** it.

| Value | The response holds |
|---|---|
| `after` (default) | The row as it is now, with the fields you changed. |
| `before` | The row as it was, so you can show or log what changed. The update happens all the same. |

```text
PUT /api/schema/admin/mysql8/inventory/customers/update-by-id/1?returnDocument=before
```

```json title="Body"
{ "pincode": 382330 }
```

```json title="Response with returnDocument=before"
{
    "success": true,
    "statusCode": 200,
    "data": { "customer_id": 1, "first_name": "Bob", "last_name": "Lin", "pincode": 382345 }
}
```

- It only changes the response, never what is written.
- It works with `select` and `deep` : both apply to the version returned.
- From code : `g.sys.db.updateById({ ..., returnDocument: 'before' })`.

    <a href="/v1/docs/apis-all/query-params/upsert.html">upsert</a>
    <a href="/v1/docs/apis-all/schema-apis/auto-generated-schema-based-update-by-id-api.html">Update by id</a>
