# REST API

With the REST API, your own code can do what you do in the Unspar web app: start an article, read the finished text and publish it to your site.

Web version: https://www.unspar.com/docs/api/

The Unspar REST API lets you connect Unspar to your own systems. Your scripts can start articles from a list of topics, your content system can pull finished articles in as Markdown, and your server can publish them once someone has reviewed them.

The API works on the same data as the web app. A project you create through the API shows up in [Projects](https://app.unspar.com/projects), and an article you start shows up in [Articles](https://app.unspar.com/articles). In Unspar, a project is a single website with its own settings and articles.

The API is included in every plan, including the free one. Starting an article through the API costs the same number of credits as starting one in the web app. Credits are how you pay in Unspar, and [Credits and prices](https://www.unspar.com/docs/guides/credits-and-prices/) explains how they work.

## Get an API token

Every request needs an API token. Tokens are tied to your team, so they keep working when team members change. Only the team owner and administrators can create them.

1. Open [Settings](https://app.unspar.com/settings) and choose **API tokens**.
2. Under **Token name**, type a name that says where the token will be used, like "Website server".
3. Choose **Create**.
4. Copy the token from the window that opens. Unspar shows it only once.

If you leave **Restrict access** unchecked, the token gets **Full access** to all projects and never expires. That is plenty for trying out the API. If you check **Restrict access** before you choose **Create**, you can narrow down what it can do:

- **Preset** sets what the token is allowed to do.
- **Project scope** sets which projects it can reach.
- **Expiration** sets when it stops working.

[API keys and connections](https://www.unspar.com/docs/agents/access/) explains these options in detail.

![Create API token form with Token name, Restrict access, the Preset choices, Project scope, Expiration and the Create button](https://www.unspar.com/images/docs/api-tokens-form.webp)

Name the token, decide whether to restrict it, then choose Create.

Store the token in a password manager or your server's secret store. If you lose it, rotate the token on the same page and switch to the new one.

## How do I send a request?

All endpoints live under one base URL:

```text
https://app.unspar.com/api/v1
```

Send your token with every request as a bearer token in the `Authorization` header. The examples in these docs read it from an environment variable:

```sh
export UNSPAR_API_KEY="paste-your-token-here"
```

When a request includes a body, send it as JSON with the `Content-Type: application/json` header. Responses come back as JSON, with the result inside the `data` field. You can read more about the format, error codes, and rate limits in [Conventions and errors](https://www.unspar.com/docs/api/conventions/).

## Send a first request

`GET /whoami` is the easiest place to start. It shows which team the token belongs to, which projects it can reach, and what it is allowed to do. If something is wrong with your token, you'll find out right away.

```sh
curl https://app.unspar.com/api/v1/whoami \
  -H "Authorization: Bearer $UNSPAR_API_KEY"
```

Next, list your projects. Most other calls need a project's `id`, so copy the one you want to work with.

```sh
curl https://app.unspar.com/api/v1/projects \
  -H "Authorization: Bearer $UNSPAR_API_KEY"
```

An ID is a string of 26 letters and digits, like `01JX9Q3M4N5P6R7S8T9V0W1X2Y`.

## Where do I go next?

Most integrations follow the same path. Each page below walks through one part of it and ends with the full endpoint reference.

1. [Articles](https://www.unspar.com/docs/api/articles/): check the price, start an article, wait for it, read the text, and publish it.
2. [Projects and ideas](https://www.unspar.com/docs/api/projects/): create projects, change their settings, turn on Project Auto, and find article ideas.
3. [Templates and voices](https://www.unspar.com/docs/api/templates/): pick the kind of article and how it sounds.
4. [Outlets](https://www.unspar.com/docs/api/outlets/): connect the sites where articles get published.
5. [Credits and API keys](https://www.unspar.com/docs/api/credits/): read the balance and the history, and manage tokens from code.

## What can't the API do?

A few features are only available in the web app:

- refreshing an existing article
- importing the posts that are already on your site
- approving images
- creating a batch of articles from a list
- the template assistant
- sorting out a publishing attempt with an unclear result

## Where is the OpenAPI document?

The [OpenAPI document](https://app.unspar.com/api/v1/openapi.yaml) describes every endpoint along with its fields and responses. You can use it to generate a client or hand it to your AI tool. The [operation map](https://app.unspar.com/api/v1/operations) lists each operation and the permission it needs. Neither requires a token.

If you'd rather not write HTTP calls yourself, the [CLI](https://www.unspar.com/docs/cli/) does the same work from a terminal and prints JSON for scripts. AI tools like Claude Code connect through the [MCP server](https://www.unspar.com/docs/mcp/).
