# Private Message Send API

**URL:** https://meta.discourse.org/t/private-message-send-api/27593
**Category:** Support
**Created:** [April 15, 2015, 12:44pm UTC](https://meta.discourse.org/t/private-message-send-api/27593 "2015-04-15T12:44:59Z")
**Posts on this page:** 2
**Page:** 2

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [April 26, 2021, 4:20pm UTC](https://meta.discourse.org/t/private-message-send-api/27593/21 "2021-04-26T16:20:59Z")

</div>

Are you setting the archetype? In the future if you include the request you are sending, it’ll be easier to help you.

The following example works for me:

```plaintext
curl https://$DISCOURSE_HOSTNAME/posts \
  -H "api-key: $DISCOURSE_API_KEY" \
  --data 'title=Testing PM creation&archetype=private_message&target_recipients=user1,user2' \
  --data-urlencode 'raw=PM body, long enough to meet site rules & may be complex ♥'

```

ℹ if you are using an `all_users` API key you also need to specify `api-username`

---

<div class="post-metadata">

### Author: ![RogerBW](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@RogerBW](https://meta.discourse.org/u/RogerBW)
#### Post date: [April 26, 2021, 4:44pm UTC](https://meta.discourse.org/t/private-message-send-api/27593/22 "2021-04-26T16:44:08Z")

</div>

Thanks, that’s sorted it! No, since the API documentation didn’t list `archetype` as required (not even “required for private message” the way `target_usernames` is) or say anything about what it was for I wasn’t messing with it.

Anyway, this now works, and for the reference of anyone who comes across the same problem (particuarly if using POST) the JSON-encoded body elements in my working request are:

| key | value |
| --- | --- |
| raw | the raw message text |
| title | the message/thread title |
| target\_usernames | comma-separated list of usernames |
| archetype | the literal string `private_message` |

This is sent as the body of a POST to `/posts.json` with the custom header fields

| key | value |
| --- | --- |
| Content-Type | `application/json; charset=UTF-8` |
| Api-Key | key data |
| Api-Username | the username |

[Previous page](https://meta.discourse.org/t/private-message-send-api/27593.md?page=1)
