Is it possible to send a private message through the API?
It appears you may only view direct (private) messages, not create them. The API repository @ GitHub shows only viewing abilities (GET).
Why do you want to create a private message via API? What is your scenario for wanting this feature?
You can create them. URL structure is sorta like this:
Send a private message and with Chrome developer tools watch the Network tab. (You can learn a lot of neat functionality doing that.)
The API key can be used via URL? That doesn’t sound safe.
The API + curl allows something to be posted at the server level, bypassing the client/browser layer, which is safer than exposing the API key via html link. Someone only needs to check the dev tools as you did and grab it.
However, this depends on what exactly @Stackfish wants this for.
A PM is just a type of post, you can create a PM just fine using the API. In fact we are using the API on this very site to create PMs.
PM stands for personal message by the way
Can't send PM via API (HTTPUnprocessableEntity 422)
But via URL or curl? A URL would expose the API key, correct?
Via Discourse api gem or curl or whatever.
Only if it’s transported over unsecured HTTP, in which case an intercepting observer could have grabbed the form data anyways.
@AdamCapriola Thanks that’s a cool trick and that should meet my needs.
@purldator The reason I’m looking into this is that we are using Discourse as the forum for a larger community. We would like to use discourse as the primary mechanism for messaging and alerts within in our community.
For example, it would be really cool if Stackfish could send a notification (or private message) every time one of our user’s gets a buddy request or one of their stories in liked. These notifications would be system generated.
Thanks to everyone!
Is this a POST or a GET? I tried sending this as a GET and I receive a 200 response but no message is created. Does this still work?
I just needed to send the request as a POST
Sorry I haven’t gotten around to implementing this yet so I’m not sure.
Hi Adam! Trust all is well with you.
Do you know if there a way to auto archive messages sent via API? Or if not, could such an option be added to the API @codinghorror?
We are getting alot of these API generated messages and we only need to see them when they are replied to, which would put them back in the inbox. For now we are manually selecting all and archiving them. It would be nice to skip that manual step.
Since you are creating private message via API call, you could also change the topic status:
It looks like
enabled=true sets the archived flag.
awesome! Thanks for looking into this. I tried it though, and unless I’m getting something wrong I think this is not working for personal messages - maybe the statuses work differently for messages than topics?
I’m sorry to hear that! I’ve been looking into the APIs for a similar purpose - feeding private messages into the system and managing them. It sounds like there are some bugs that might make this difficult - did you report that status changes didn’t work on PMs?
Hi Brian! I don’t think this is a bug necessarily - more that I am not understanding the difference between messages and topics. Unlike topics, which can be archived for everyone, messages have an inbox and an archive for each user (and for each group) included in the message. So there’s likely another field for tracking that for each user.
I had a quick dig in the data explorer and indeed see there are
group_archived_messages tables but don’t really know what that means or how they work, or if it’s actually possible via the API to place an outgoing message in the sender’s archive or a group’s archive by default but in the inbox for the intended recipient.
Anyhoo this is not the highest priority for me as I have found a workflow with the current setup that seems to work for my team. If you do figure it out, let me know!