# Save To Collection

This endpoint can be used to insert or update a document inside a Xenioo Database Collection. Documents inside a collection are specified as pure JSON payloads.

### Requirements

To successfully invoke this endpoint :

1. A [Bot Level Authorization Token](https://docs10.xenioo.com/xenioo-api/globa-platform-api/authorization#bot-level-token-request) must be created and sent in the header.
2. An active Database package must be active on the target account.
3. The desired [collection ](https://docs10.xenioo.com/database/collections)must exist and must be flagged as [accessible through API](https://docs10.xenioo.com/collections#enable-api-access).

### Request

The following request shows how to insert a new document inside a Xenioo Database Collection:

```bash
curl --location --request POST 'https://<NODE>.xenioo.com/data/<COLLECTIONNAME>' \
--header 'Authorization: Bearer <BOT AUTH TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{
	  "Color":"Red",
    "Value":123
}'
```

As long as the supplied JSON payload is valid, it will be inserted in the target collection, regardless of the structure of other existing documents.&#x20;

If supplied, the **\_id** field will be used to update a specific document. If the document does not exist a new document will be created and assigned the supplied id.

### Response

If successful, the unique id of the affected document will be returned.

```bash
{
    "id":"<some unique id>"
}
```

### Response Codes

This endpoint will reply with the following standard HTTP codes.

| Code | Meaning                                                                   |
| ---- | ------------------------------------------------------------------------- |
| 200  | Ok. The request has been successfully fulfilled.                          |
| 400  | Bad Request. The call does not contain the data required to be fulfilled. |
| 404  | Not Found. The specified collection has not been found.                   |
| 403  | Unauthorized. The specified collection cannot be access through API       |
