# Create a diagram in the editor

> Page: https://docs.plotwork.dev/api/post-user-diagrams. Index of every page: https://docs.plotwork.dev/llms.txt

The first Save of a diagram made in the portal's editor.

`POST /user/diagrams`

## TL;DR

| Question | Answer |
|---|---|
| What does it do? | Create a diagram in the editor. |
| What does it take? | A JSON body of type [`CreateDiagramBody`](https://docs.plotwork.dev/api/schemas.md#creatediagrambody). |
| What does it return? | Status 200 with a body of type [`CreatedDiagram`](https://docs.plotwork.dev/api/schemas.md#createddiagram). |
| What can go wrong? | `400` the body is not valid; `401` not signed in; `403` the plan does not include the editor (plan.editor_not_included), the plan has no room (hosting.quota_exceeded), the organisation refuses the folder or the role, or the request came from an origin that may not make changes; `409` several organisations claim the account's publishes and none is the default (orgs.publish_ambiguous); `413` the body is larger than the size cap, or the diagram renders larger than the plan hosts; `422` the diagram source has errors; the diagnostics are in details; `429` too many requests; `502` the diagram could not be stored; `503` hosting is not set up on this server. Every failure uses the one error envelope. |

## What it does

The first Save of a diagram made in the portal's editor. Draws the source with the source written in, and stores it where the account's publishes go: its own library, or an organisation's private library when its Publishing setting says so (private: true). Needs a plan with the diagram editor (403 plan.editor_not_included).

## Request body

The body has the type [`CreateDiagramBody`](https://docs.plotwork.dev/api/schemas.md#creatediagrambody).

| Field | Type | Required | Description |
|---|---|---|---|
| `source` | `string` | yes | Diagram source; the first line is the header, such as flow "Title" (draw_diagram lists every kind). at least 1 character; at most 50000 characters. |
| `scheme` | `"light" \| "dark" \| "auto"` | no | The color scheme to draw it in: light, dark, or auto. Light when left out. |
| `name` | `string` | no | A label for the diagram in your list and in the Markdown snippet. Optional. at least 1 character; at most 80 characters; pattern `^[^\p{Cc}]+$/u`. |
| `folder` | `string \| null` | no | The folder to file the diagram in. Left out, a new diagram goes to the top level and a diagram that is already hosted stays where it is. A path files a new diagram there, or moves the one that is already hosted and keeps its link. null puts it at the top level. |

## Responses

| Status | Meaning | Body |
|---|---|---|
| 200 | The same picture was already stored; it was kept. | [`CreatedDiagram`](https://docs.plotwork.dev/api/schemas.md#createddiagram) |
| 201 | The diagram was stored. | [`CreatedDiagram`](https://docs.plotwork.dev/api/schemas.md#createddiagram) |
| 400 | The body is not valid. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 401 | Not signed in. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 403 | The plan does not include the editor (plan.editor_not_included), the plan has no room (hosting.quota_exceeded), the organisation refuses the folder or the role, or the request came from an origin that may not make changes. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 409 | Several organisations claim the account's publishes and none is the default (orgs.publish_ambiguous). | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 413 | The body is larger than the size cap, or the diagram renders larger than the plan hosts. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 422 | The diagram source has errors; the diagnostics are in details. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 429 | Too many requests. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 502 | The diagram could not be stored. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 503 | Hosting is not set up on this server. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |

## Response body

A 200 answer has the type [`CreatedDiagram`](https://docs.plotwork.dev/api/schemas.md#createddiagram).

| Field | Type | Required | Description |
|---|---|---|---|

## See also

| Doc | Why |
|---|---|
| [API reference](https://docs.plotwork.dev/api/reference.md) | Every endpoint, and the error envelope |
| [Schemas](https://docs.plotwork.dev/api/schemas.md) | Every request and response type |
| [Tool reference](https://docs.plotwork.dev/mcp/tools.md) | The operations as callable tools |
