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

# Create Snippet

> Save a snippet or hashtag group in a workspace

## Create Snippet

Saves a snippet or hashtag group in a workspace, so your team can drop it into posts from the composer. Every plan has snippets, Free included. A workspace keeps at most 500.

### Request

**workspace\_id** `integer` *required*

The ID of the workspace the snippet belongs to

**kind** `string` *required*

`snippet` for any saved text, `hashtags` for a hashtag group

**name** `string` *required*

Short name shown in the list, 1 to 80 characters after spaces at the start and end are removed. Names need not be unique.

**body** `string` *required*

The text that goes into the post, up to 5,000 characters

```json theme={null}
{
  "workspace_id": 12,
  "kind": "hashtags",
  "name": "Launch tags",
  "body": "#launch #buildinpublic #saas"
}
```

### Response

`201 Created` with the new [snippet object](https://docs.postsyncer.com/api-reference/snippets/overview.md#the-snippet-object).

```json theme={null}
{
  "id": 31,
  "workspace_id": 12,
  "kind": "hashtags",
  "name": "Launch tags",
  "body": "#launch #buildinpublic #saas",
  "created_by": 7,
  "created_at": "2026-11-17T09:12:44+00:00",
  "updated_at": "2026-11-17T09:12:44+00:00"
}
```

### Code Examples

```bash cURL theme={null}
curl -X POST "https://postsyncer.com/api/v1/snippets" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workspace_id": 12,
    "kind": "hashtags",
    "name": "Launch tags",
    "body": "#launch #buildinpublic #saas"
  }'
```

```javascript Node.js theme={null}
const axios = require('axios');

const createSnippet = async () => {
  try {
    const response = await axios.post('https://postsyncer.com/api/v1/snippets', {
      workspace_id: 12,
      kind: 'hashtags',
      name: 'Launch tags',
      body: '#launch #buildinpublic #saas'
    }, {
      headers: {
        'Authorization': 'Bearer YOUR_API_TOKEN',
        'Content-Type': 'application/json'
      }
    });

    console.log('Snippet saved:', response.data);
  } catch (error) {
    console.error('Error saving snippet:', error.response?.data || error.message);
  }
};

createSnippet();
```

```php PHP theme={null}
<?php

$data = [
    'workspace_id' => 12,
    'kind' => 'hashtags',
    'name' => 'Launch tags',
    'body' => '#launch #buildinpublic #saas'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://postsyncer.com/api/v1/snippets');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_TOKEN',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode === 201) {
    $snippet = json_decode($response, true);
    echo "Snippet saved: " . $snippet['id'];
} else {
    echo "Error: " . $response;
}
?>
```

```python Python theme={null}
import requests

data = {
    'workspace_id': 12,
    'kind': 'hashtags',
    'name': 'Launch tags',
    'body': '#launch #buildinpublic #saas'
}

headers = {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
}

response = requests.post(
    'https://postsyncer.com/api/v1/snippets',
    json=data,
    headers=headers
)

if response.status_code == 201:
    snippet = response.json()
    print(f"Snippet saved: {snippet['id']}")
else:
    print(f"Error: {response.status_code}")
    print(response.text)
```

### Error Codes

**401** `Unauthorized`

Missing or invalid API token

**403** `Forbidden`

The key does not have the `snippets:create` permission, or the key's person's role in the workspace does not allow creating snippets

**422** `Unprocessable Entity`

Validation errors: an unknown `workspace_id` or one the key's person is not in, a `kind` other than `snippet` or `hashtags`, a `name` over 80 characters, an empty or over-5,000-character `body`. Also when the workspace already keeps 500 snippets: `This workspace has 500 saved snippets, the most it can keep. Delete one to save another.`


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