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:
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
3 Likes
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 |
2 Likes