# Update X account

> Turn an X account's billed background reads on or off.

Canonical: <https://www.tryadeli.com/docs/api/accounts/update-x-account>

`PATCH https://app.tryadeli.com/api/v1/profiles/{profileId}/accounts/{accountId}`

Authorization: `Bearer <API key>` — see [Authentication](https://www.tryadeli.com/docs/authentication)

Every X read is billed to you ([X API pricing](https://www.tryadeli.com/docs/pricing/x)), so the reads that
would run in the background on an X account are off until you turn them on:
`analytics` (post metrics and follower counts) and `inbox` (direct messages).
Neither syncs anything yet; the switches are stored so that both features
respect them when they arrive. Publishing and deleting always work.

**Path parameters**

| Name        | Type   | Required | Description                                                                                                                                  |
| ----------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `profileId` | `uuid` | Yes      | A profile in your organization. Any other value returns 404 profile\_not\_found.                                                             |
| `accountId` | `uuid` | Yes      | An X account in that profile. Another platform's account returns 400 unsupported\_platform; any other value returns 404 account\_not\_found. |

**Body**

| Name            | Type     | Required | Description                                                                                      |
| --------------- | -------- | -------- | ------------------------------------------------------------------------------------------------ |
| `xCapabilities` | `object` | Yes      | `{ analytics?: boolean, inbox?: boolean }`, at least one. Fields you leave out keep their value. |

Returns the account with its updated `xCapabilities`. Turning `inbox` on needs
the `dm.read` and `dm.write` permissions, which a connection made today has not
granted: that returns `409 reconnect_required` with the missing scopes in
`details.missingScopes`.

**Errors** — `401 unauthorized`, `400 invalid_request`, `400 unsupported_platform`
(not an X account), `404 profile_not_found`, `404 account_not_found`,
`409 reconnect_required`, `502 database_error`.

## Request examples

**cURL**

```bash
curl --fail-with-body -X PATCH "https://app.tryadeli.com/api/v1/profiles/00000000-0000-4000-8000-000000000001/accounts/00000000-0000-0000-0000-000000000000" \
  -H "Authorization: Bearer $ADELI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "xCapabilities": {
    "analytics": true
  }
}'
```

**JavaScript**

```javascript
const response = await fetch("https://app.tryadeli.com/api/v1/profiles/00000000-0000-4000-8000-000000000001/accounts/00000000-0000-0000-0000-000000000000", {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.ADELI_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    xCapabilities: {
      analytics: true,
    },
  }),
});
console.log(await response.json());
```

**Python**

```python
import os

import requests

response = requests.patch(
    "https://app.tryadeli.com/api/v1/profiles/00000000-0000-4000-8000-000000000001/accounts/00000000-0000-0000-0000-000000000000",
    headers={"Authorization": f"Bearer {os.environ['ADELI_API_KEY']}"},
    json={
        "xCapabilities": {
            "analytics": True,
        },
    },
)
print(response.json())
```

## Responses

### 200

```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "accountId": "00000000-0000-0000-0000-000000000000",
  "profileId": "00000000-0000-4000-8000-000000000001",
  "platform": "x",
  "providerId": "1234567890",
  "displayName": "Adeli",
  "displayIdentifier": "adeli",
  "connectionStatus": "connected",
  "xCapabilities": { "analytics": true, "inbox": false }
}
```

### 409

```json
{
  "error": {
    "code": "reconnect_required",
    "message": "Reconnect this X account to grant dm.read, dm.write",
    "details": { "missingScopes": ["dm.read", "dm.write"] }
  }
}
```
