Unable to send a PM via DiscourseApi - "errors"=>["You must select a valid user."]

This used to work, but recently on trying to send a PM using the DiscourseApi I keep getting: DiscourseApi::UnprocessableEntity ({"action"=>"create_post", "errors"=>["You must select a valid user."]}) but the user is valid (and the same thing happens no matter which username I try).

Via a console using the Discourse gem:

user = "MyUserName"
client = DiscourseApi::Client.new("https://myforum.com")
client.api_key = "h03873hxjd734i4hdjdudje94udjdjdeje83483483jdjdjdjed84u34e"
client.api_username = "ForumUserName"

client.create_private_message(
  title: "testing a title",
  raw: "Hey this is a test",
  target_usernames: user
)

Looks like a bug? (Think there was a similar bug with tags a while back : /)

1 Like

Hi Aston,

It looks like target_usernames has been deprecated.

Try target_recipients instead! :slight_smile:

https://docs.discourse.org/#tag/Private-Messages

5 Likes

Just a note to say you need to use create_pm as well (instead of create_private_message).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.