function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
swintonswinton 

How to mention a user (@-mention) via the Chatter API?

Hi all,

 

I'm trying to figure out how I can @-mention a user via the Chatter API.. none of the following seem to work:

 

  • mentioning @[Steve Winton] # user's name in square brackets
  • mentioning @(Steve Winton) # user's name in round brackets
  • mentioning @"Steve Winton" # user's name in quotes
  • mentioning @{005E0000000Fpox} # user's ID in curly braces
  • mentioning @005E0000000Fpox # user's ID without curly braces

Is there a specific convention for this I should follow?

 

Many thanks,

Steve

Best Answer chosen by Admin (Salesforce Developers) 
ChrisOctagonChrisOctagon

You cannot @-mention using the simple "text" query parameter. To @-mention a user via the Chatter REST API you must provide a JSON or XML input. The JSON and XML inputs can provide a list of input message segments. Remember to set your "Content-Type" header to "application/json" or "application/xml" to provide this input successfully.

 

For example the following JSON input includes an @-mention:

 

{

"body": [ 

     { "type":"Text", "text" : "Hello... "},

     {"type":"Mention", "id": "00523423423434"},

     { "type":"Text", "text": " welcome to Salesforce"} ]

}

All Answers

ChrisOctagonChrisOctagon

You cannot @-mention using the simple "text" query parameter. To @-mention a user via the Chatter REST API you must provide a JSON or XML input. The JSON and XML inputs can provide a list of input message segments. Remember to set your "Content-Type" header to "application/json" or "application/xml" to provide this input successfully.

 

For example the following JSON input includes an @-mention:

 

{

"body": [ 

     { "type":"Text", "text" : "Hello... "},

     {"type":"Mention", "id": "00523423423434"},

     { "type":"Text", "text": " welcome to Salesforce"} ]

}

This was selected as the best answer
swintonswinton

Thanks for the reply.

 

This surprises me, I would expect Chatter to be able to parse @-mentions directly from plain text, any idea if this is planned?

ChrisOctagonChrisOctagon

Sorry, we don't pull from plaintext because customers may have scenarios where they wish to make use of square brackets for some other purpose, and also because we have no way of handling collisions. If there are multiple John Smiths then we don't know how to resolve [John Smith].