> ## Documentation Index
> Fetch the complete documentation index at: https://docs.link4sync.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Subaccounts

> Independent OAuth clients for your producers and consumers, so services never use your account password.

A subaccount is an OAuth client of its own, tied to one topic. Your service gets tokens with the **client credentials** flow, so it never needs your Link4Sync email or password, and you can revoke it at any time without touching anything else.

> [!TIP]
>
> Use subaccounts for services and devices. They are also the way to use OAuth if you signed up with
> Google or Microsoft: those accounts have no Link4Sync password, so the password flow in [HTTPS
> with OAuth](https://docs.link4sync.com/en/publish/https-oauth.md) does not apply to them.

## Roles

| Role | Can do |
| - | - |
| **Producer** | Write to its topic only. |
| **Consumer** | Read its topic, plus other topics you allowed on the Consumers page (see [Read access](https://docs.link4sync.com/en/manage/read-access.md)). |

## Create a subaccount

**1. Open the OAuth tab**

On the topic card, open **Endpoints and credentials**, choose HTTPS, MQTT, or MQTTS, and set **Authentication method** to OAuth. The **Subaccounts** section lists the topic's existing subaccounts.

**2. Pick a role**

Choose **Consumer (reads)** or **Producer (writes to …)**. For a consumer, tick the topics under **Also read from**. Only topics you already allowed in [Read access](https://docs.link4sync.com/en/manage/read-access.md) appear there.

**3. Create it and copy the secret**

Click **Create subaccount**. The card shows the **Client ID**, **Client secret**, and **Token endpoint**.

> [!WARNING]
>
> The client secret is shown only once and is not stored in the dashboard. Copy it into your secret store before you click **I saved the secret**.

## Get a token

Store the three values as environment variables and request a token:

```sh theme={null}
TOKEN=$(curl -s "$LINK4SYNC_TOKEN_ENDPOINT" \
  -d grant_type=client_credentials \
  --data-urlencode "client_id=$LINK4SYNC_CLIENT_ID" \
  --data-urlencode "client_secret=$LINK4SYNC_CLIENT_SECRET" | jq -r .access_token)
```

Tokens are short-lived. Request a new one when you get `401`.

## Read with a consumer subaccount

Connect over MQTT with the topic ID as the username and the token as the password, then subscribe to `<topic ID>/out`. See [Read messages](https://docs.link4sync.com/en/read-messages.md).

## Publish with a producer subaccount

Over MQTT, use the token as the password, see [Publish over MQTT](https://docs.link4sync.com/en/publish/mqtt.md). Over HTTPS, send it as a bearer token, exactly as in [HTTPS with OAuth](https://docs.link4sync.com/en/publish/https-oauth.md):

```sh theme={null}
curl -i -X POST "$LINK4SYNC_URL" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"temperature": 21.5}'
```

A successful publish returns **`202 Accepted`**.

## Delete a subaccount

Click the trash icon next to the subaccount and confirm. Its client stops working immediately, tokens it already received stop working too, and it cannot be restored. Create a new subaccount if you need access again.

## Limits

* A consumer subaccount can read at most 25 topics: its own topic plus up to 24 others.
* A producer subaccount cannot be given other topics.
* You can only grant topics that belong to your account.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.