# Outlets

An outlet is a place where Unspar sends finished articles, like your WordPress site or a GitHub repository. With these endpoints, your code sets up outlets and checks that they work.

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

Before Unspar can publish an article, it needs to know where to send it. That destination is called an outlet. You set it up once with the address and login details Unspar needs, then publish articles to it by ID using [`POST /articles/{article}/publish`](https://www.unspar.com/docs/api/articles/#publish-the-article).

Outlets are shared across your whole team, so your token needs access to all projects to create or change them. You can also see them under [Outlets](https://app.unspar.com/outlets) in the web app.

## Create an outlet

To create an outlet with `POST /outlets`, send a `name`, a `type`, and two objects:

- `connection` holds non-secret settings, such as the site address.
- `credentials` holds secret values, such as a password or token.

Unspar encrypts your credentials before storing them and never returns them in API responses. Here is an example that connects a WordPress site:

```sh
curl -X POST https://app.unspar.com/api/v1/outlets \
  -H "Authorization: Bearer $UNSPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My blog",
    "type": "wordpress",
    "connection": { "api_url": "https://example.com/wp-json" },
    "credentials": {
      "username": "editor",
      "password": "abcd efgh ijkl mnop qrst uvwx"
    }
  }'
```

Each `type` requires different fields. The linked guides show where to find each value on your site.

| `type`      | `connection`                                                                                                                                    | `credentials`                                                                                                               | Guide                                                          |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| `wordpress` | `api_url`: the address of the site's REST API, usually ending in `/wp-json`.                                                                    | `username`: a WordPress user. `password`: an application password for that user (rather than their regular login password). | [WordPress](https://www.unspar.com/docs/guides/wordpress/)                           |
| `ghost`     | `api_url`: the address of the site.                                                                                                             | `api_key`: an Admin API key from a custom integration in Ghost.                                                             | [Outlets and publishing](https://www.unspar.com/docs/guides/outlets-and-publishing/) |
| `github`    | `owner` and `repo`: the repository. `branch`: an existing branch. `directory`: the folder where files go (leave it out to use the root folder). | `api_key`: a fine-grained token with read and write access to the repository's contents.                                    | [GitHub](https://www.unspar.com/docs/guides/github/)                                 |
| `webhook`   | `api_url`: a public HTTPS address.                                                                                                              | `api_key`: a signing secret that your receiver also knows.                                                                  | [Webhooks](https://www.unspar.com/docs/guides/webhooks/)                             |

Email outlets are easiest to set up under [Outlets](https://app.unspar.com/outlets) in the web app, where you can see all their options. You can't add new Medium outlets, though existing ones keep working.

## Keep secrets out of your files

Avoid committing files with credentials to your repository. If you create outlets with the [CLI](https://www.unspar.com/docs/cli/), pass `--secret-field` to hide secret values in the command output. They appear as `[REDACTED]` in previews and error messages:

```sh
unspar api post /outlets --body-file github-outlet.json --secret-field api_key
```

## Test an outlet

`GET /outlets` returns your outlets without their secrets. The `ready` field tells you whether an outlet has all the required settings, and `readiness_reason` explains what is missing. Neither confirms that the connection still works, so you need to run a test for that.

`POST /outlets/{outlet}/test` tests the connection and saves the result. What it checks depends on the outlet type:

| Outlet    | What the test does                                                                             |
| --------- | ---------------------------------------------------------------------------------------------- |
| WordPress | Logs in and reads posts.                                                                       |
| GitHub    | Reads the repository and the branch.                                                           |
| Webhook   | Checks the address and confirms a secret is stored, without sending anything to your receiver. |
| Email     | Sends a test email.                                                                            |

You can check the outcome of the most recent test in the outlet's `last_connection_test` field.

## Change or delete an outlet

`PATCH /outlets/{outlet}` updates only the fields you include. If you omit `credentials`, your stored secrets stay as they are. To remove a stored secret, list it in `clear_credentials`:

```json
{ "clear_credentials": { "api_key": true } }
```

`DELETE /outlets/{outlet}` removes the outlet. Unspar blocks the deletion if articles still point to the outlet or if a Project Auto publishes to it, and the response tells you what is in the way. Any projects that used the outlet as their default lose that setting, and the response lists them in `cleared_project_defaults`.

## Find out what a site runs

`POST /outlets/detect` takes a site's address in `input`, checks whether the site runs WordPress or Ghost, and suggests the API address to use. It doesn't save anything. The web app runs this same check on the **Assistant** tab when you add an outlet.

For details on what each kind of outlet receives when you publish, see [Outlets and publishing](https://www.unspar.com/docs/guides/outlets-and-publishing/).

## Endpoint reference

### GET /api/v1/outlets

`listOutlets`: List publishing outlets without credentials.

Permission: `unspar:outlets:read`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `page` | query | integer | no | Minimum 1. |
| `per_page` | query | integer | no | Minimum 1. Maximum 100. |
| `q` | query | string | no |  |
| `provider_type` | query | "wordpress", "medium", "ghost", "email", "github", "webhook" | no |  |
| `ready` | query | boolean | no |  |
| `default_for_project` | query | string | no |  |
| `sort` | query | "created_at", "-created_at", "name", "-name" | no |  |

Responses: 200 Publishing outlet list.

### POST /api/v1/outlets

`createOutlet`: Create a publishing outlet. Credentials are write-only.

Permission: `unspar:outlets:write`

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | no |  |
| `type` | "wordpress", "medium", "ghost", "email", "github", "webhook" | no |  |
| `connection` | object | no |  |
| `credentials` | object | no |  |
| `selection` | object | no |  |
| `defaults` | object | no |  |
| `clear_credentials` | object | no |  |

Responses: 201 Publishing outlet.

### POST /api/v1/outlets/detect

`detectOutlet`: Detect a publishing provider from a public URL without saving it.

Permission: `unspar:outlets:write`

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `input` | string | yes |  |

Responses: 200 Outlet provider detection result.

### GET /api/v1/outlets/{outlet}

`getOutlet`: Show one publishing outlet without credentials.

Permission: `unspar:outlets:read`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `outlet` | path | string | yes |  |

Responses: 200 Publishing outlet.

### PATCH /api/v1/outlets/{outlet}

`updateOutlet`: Update a publishing outlet. Omitted credentials are preserved.

Permission: `unspar:outlets:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `outlet` | path | string | yes |  |

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | no |  |
| `type` | "wordpress", "medium", "ghost", "email", "github", "webhook" | no |  |
| `connection` | object | no |  |
| `credentials` | object | no |  |
| `selection` | object | no |  |
| `defaults` | object | no |  |
| `clear_credentials` | object | no |  |

Responses: 200 Publishing outlet.

### DELETE /api/v1/outlets/{outlet}

`deleteOutlet`: Delete a publishing outlet when article and Project Auto safeguards allow it.

Permission: `unspar:outlets:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `outlet` | path | string | yes |  |

Responses: 200 Outlet deletion result.

### POST /api/v1/outlets/{outlet}/test

`testOutlet`: Run and persist a sanitized connection test for an outlet.

Permission: `unspar:outlets:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `outlet` | path | string | yes |  |

Responses: 200 Outlet connection test result.
