# Content API

Use the Content API to interact with your documents

## Endpoint

### URL

`https://content.tipe.io/:projecId/:environment`

`Route Params`

| Param      | Type    | Default | Description                                          |
|------------|---------|---------|------------------------------------------------------|
| **projectId** | `string` | -       | Your Tipe Project Id                               |
| **environment** | `string` | -       | The name of your Tipe Environment                   |

### Authentication

If you want to query a private Tipe environment or draft content, then you need an API Key. Use the `Authorization` header. You can create an API Key using the CLI.

## Documents

## Get All Documents

This endpoint retrieves paginated documents

#### HTTP Request

`GET /document`

`Query Params`

| Param      | Type    | Default | Description                                          |
|------------|---------|---------|------------------------------------------------------|
| **type**      | `string` | -       | The document type                                   |
| **draft**    | `boolean` | `false` | Return draft documents                               |
| **limit**    | `number` | `50`    | Limit of documents to return                         |
| **page**     | `number` | `1`     | Page for pagination                                  |
| **fields**   | `Object` | `{}`    | Filter on document fields                            |

## Get One Document

This endpoint retrieves one Document

#### HTTP Request

`GET /document/:id`

`Route Params`

| Param      | Type    | Default | Description                                          |
|------------|---------|---------|------------------------------------------------------|
| **id**      | `string` | -       | The Id of the document you want                     |

`Query Params`

| Param      | Type    | Default | Description                                          |
|------------|---------|---------|------------------------------------------------------|
| **draft**    | `boolean` | `false` | Return the latest draft                              |

## Create Document

This endpoint creates a Document

#### HTTP Request

`POST /document`

`Body Fields`

| Field   | Type    | Default        | Description                                      |
|---------|---------|----------------|-------------------------------------------------|
| `name`  | `string` | -              | Name of your document                           |
| `type`  | `string` | -              | Type of document to create. Referred to as ID in your schema on a document type. |
| `id`    | `string` | `<generated>`  | Set a non changeable custom ID for this document. |
| `fields`| `Object` | `{}`           | Fields to set on this document. You should them off you schema|

## Update Document

This endpoint updates a Document's fields and name

#### HTTP Request

`PATCH /document/:id`

`Route Params`

| Param      | Type    | Default | Description                                          |
|------------|---------|---------|------------------------------------------------------|
| **id**      | `string` | -       | The ID of the document you want to update           |

`Body Fields`

| Field   | Type    | Default        | Description                                      |
|---------|---------|----------------|-------------------------------------------------|
| `name`  | `string` | -              | Change document name                             |
| `fields`| `Object` | `{}`           | Fields to update. Will be merged with existing fields.|

## Replace Document

This endpoint replaces a Document's fields

#### HTTP Request

`PUT /document/:id`

`Route Params`

`Body Fields`

| Field   | Type    | Default        | Description                                      |
|---------|---------|----------------|-------------------------------------------------|
| `name`  | `string` | -              | Change document name                             |
| `fields`| `Object` | `{}`           | Fields to update. Will replace existing fields   |

## Publish Document

This endpoint publishes a Document

#### HTTP Request

`PATCH /publish/:id`

`Route Params`

| Param      | Type    | Default | Description                                          |
|------------|---------|---------|------------------------------------------------------|
| **id**      | `string` | -       | The ID of the document you want to publish. Will publish the latest draft |

## Unpublish Document

This endpoint unpublishes a Document

#### HTTP Request

`PATCH /unpublish/:id`

`Route Params`

| Param      | Type    | Default | Description                                          |
|------------|---------|---------|------------------------------------------------------|
| **id**      | `string` | -       | The ID of the document you want to unpublish       |

## Archive Document

This endpoint archives a Document

#### HTTP Request

`DELETE /document/:id`

`Route Params`

| Param      | Type    | Default | Description                                          |
|------------|---------|---------|------------------------------------------------------|
| **id**      | `string` | -       | The ID of the document you want to archive. Will unpublish document before archiving.
