# Creates a new topic, a new post, or a private message

`POST /posts.json`

Authentication: no security requirement declared for this operation.

Request body: application/json

Type: any

- `title` (optional)
  Type: string
  
  Required if creating a new topic or new private message.

- `raw` (required)
  Type: string

- `topic_id` (optional)
  Type: integer
  
  Required if creating a new post.

- `category` (optional)
  Type: integer
  
  Optional if creating a new topic, and ignored if creating
  a new post.

- `target_recipients` (optional)
  Type: string
  
  Required for private message, comma separated.
  
  Example:
  
  ```json
  "blake,sam"
  ```

- `target_usernames` (optional)
  Type: string
  
  Deprecated. Use target_recipients instead.
  
  deprecated: true

- `archetype` (optional)
  Type: string
  
  Required for new private message.
  
  Example:
  
  ```json
  "private_message"
  ```

- `created_at` (optional)
  Type: string

- `reply_to_post_number` (optional)
  Type: integer
  
  Optional, the post number to reply to inside a topic.

- `embed_url` (optional)
  Type: string
  
  Provide a URL from a remote system to associate a forum
  topic with that URL, typically for using Discourse as a comments
  system for an external blog.

- `external_id` (optional)
  Type: string
  
  Provide an external_id from a remote system to associate
  a forum topic with that id.

- `auto_track` (optional)
  Type: boolean
  
  If false, the user will not track the topic. By default,
  the user will track the topic.

Additional properties: false

Responses:

- 200: post created

Content type: application/json

Type: any

- `id` (required)
  Type: integer

- `name` (required)
  Type: string; nullable

- `username` (required)
  Type: string

- `avatar_template` (required)
  Type: string

- `created_at` (required)
  Type: string

- `raw` (optional)
  Type: string

- `cooked` (required)
  Type: string

- `post_number` (required)
  Type: integer

- `post_type` (required)
  Type: integer

- `posts_count` (required)
  Type: integer

- `updated_at` (required)
  Type: string

- `reply_count` (required)
  Type: integer

- `reply_to_post_number` (required)
  Type: string; nullable

- `quote_count` (required)
  Type: integer

- `incoming_link_count` (required)
  Type: integer

- `reads` (required)
  Type: integer

- `readers_count` (required)
  Type: integer

- `score` (required)
  Type: number

- `yours` (required)
  Type: boolean

- `topic_id` (required)
  Type: integer

- `topic_slug` (required)
  Type: string

- `display_username` (required)
  Type: string; nullable

- `primary_group_name` (required)
  Type: string; nullable

- `flair_name` (required)
  Type: string; nullable

- `flair_url` (required)
  Type: string; nullable

- `flair_bg_color` (required)
  Type: string; nullable

- `flair_color` (required)
  Type: string; nullable

- `flair_group_id` (optional)
  Type: integer; nullable

- `badges_granted` (optional)
  Type: Array<any>
  
  Items:
    Type: any

- `version` (required)
  Type: integer

- `can_edit` (required)
  Type: boolean

- `can_delete` (required)
  Type: boolean

- `can_recover` (required)
  Type: boolean

- `can_see_hidden_post` (optional)
  Type: boolean

- `can_wiki` (required)
  Type: boolean

- `user_title` (required)
  Type: string; nullable

- `bookmarked` (required)
  Type: boolean

- `actions_summary` (required)
  Type: Array<object>
  
  Items:
    Type: object
    
    - `id` (required)
      Type: integer
    
    - `can_act` (required)
      Type: boolean
    
    Additional properties: false

- `moderator` (required)
  Type: boolean

- `admin` (required)
  Type: boolean

- `staff` (required)
  Type: boolean

- `user_id` (required)
  Type: integer

- `draft_sequence` (required)
  Type: integer

- `hidden` (required)
  Type: boolean

- `trust_level` (required)
  Type: integer

- `deleted_at` (required)
  Type: string; nullable

- `user_deleted` (required)
  Type: boolean

- `edit_reason` (required)
  Type: string; nullable

- `can_view_edit_history` (required)
  Type: boolean

- `wiki` (required)
  Type: boolean

- `reviewable_id` (required)
  Type: integer; nullable

- `reviewable_score_count` (required)
  Type: integer

- `reviewable_score_pending_count` (required)
  Type: integer

- `post_url` (required)
  Type: string

- `post_localizations` (optional)
  Type: Array<any>
  
  Items:
    Type: any

- `mentioned_users` (optional)
  Type: Array<any>
  
  Items:
    Type: any

Additional properties: false

## Examples

### cURL

```bash
curl -X POST 'https://discourse.example.com/posts.json' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "title": "string",
  "raw": "string",
  "topic_id": 0,
  "category": 0,
  "target_recipients": "blake,sam",
  "target_usernames": "string",
  "archetype": "private_message",
  "created_at": "string",
  "reply_to_post_number": 0,
  "embed_url": "string",
  "external_id": "string",
  "auto_track": true
}'
```

### JavaScript

```javascript
const body = `{
  "title": "string",
  "raw": "string",
  "topic_id": 0,
  "category": 0,
  "target_recipients": "blake,sam",
  "target_usernames": "string",
  "archetype": "private_message",
  "created_at": "string",
  "reply_to_post_number": 0,
  "embed_url": "string",
  "external_id": "string",
  "auto_track": true
}`;

const response = await fetch('https://discourse.example.com/posts.json', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "title": "string",
  "raw": "string",
  "topic_id": 0,
  "category": 0,
  "target_recipients": "blake,sam",
  "target_usernames": "string",
  "archetype": "private_message",
  "created_at": "string",
  "reply_to_post_number": 0,
  "embed_url": "string",
  "external_id": "string",
  "auto_track": true
}'''

response = requests.post(
    'https://discourse.example.com/posts.json',
    data=body.encode('utf-8'),
    headers={
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
