User mention Macro - REST API

Orlando Jurcone March 20, 2019

Hi,

 

I am trying to create a Confluence Page using REST API and mention some existing users. Do do this I am using this macro:

<ac:link>
<ri:user ri:userkey="123456789"/>
</ac:link>

It works perfectly, but I can only get my userkey. To get others I need to ask each one particularly or query database for which I don't have access.

 

I tried something like this:

<ac:link>
<ri:user ri:user="user"/>
</ac:link>

 

but I got:

{"statusCode":500,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"java.lang.RuntimeException: com.atlassian.confluence.content.render.xhtml.XhtmlException: com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}username"}
500

 

Is there a way to mention a Confluence user using Rest API with only the user name (not user-key)?

 

Thanks.

2 answers

3 votes
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2019

You are writing a user macro? If so you can try this code:

<p><ac:link>
#set($userInfo = $userAccessor.getUserByName("$userEntry"))
<ri:user ri:userkey="$userInfo.key"/>
</ac:link></p>

Where $userEntry is the user name you want is selected using the @Param XXXX|type=username

Orlando Jurcone March 22, 2019

Hi Bill,

 

Thanks for the quick response.

Unfortunately I don't have System Administrator permissions for creating new macros.  I am curios if there is one already available like this one that requires the userkey.

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 22, 2019

I am not aware of any. I guess it is time to bribe your admin to install user macros for you. ;-)

You could set up a local copy of Confluence where you can be an admin and do all your testing, so that your admin would just have to install the macro once it is done.

Jineesh M G January 28, 2020

Hi Bill,

I am able to do the same thing but once I update the comment/description with this macro, no notification received by the mentioned user. 

But if I use @ symbol along with the user notification email working fine. Any idea?

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 28, 2020

I suspect that the mention function is driven by a client-side script versus the server. In other words, the user macro will display a user name in a similar fashion, it won't trigger the mention script/autocomplete, driven by the shortcut the @ key.

However, all it not lost (maybe), as there is a user mention macro, so you could just use the storage format inside your user macro, and it should work.

Jineesh M G January 29, 2020

Hi Bill,

How can I get the storage format? I got the source code as below:

<ac:link>
      <ri:user ri:userkey="xxxxxxx" />
</ac:link>

I have implemented this but it just shown the User. No notification.

Could you please help? 

Mårten Woxberg
Contributor
November 23, 2022

Thanks @Bill Bailey 

Thought we where loosing our minds searching for the answer to this.

1 vote
Radek Janata
Contributor
November 7, 2019

Hi Orlando,

it's sufficient to use 'username' instead of 'userkey'. Confluence will transform it automatically from 'username' to 'userkey'.

<ac:link>
<ri:user ri:username="name.surname"/>
</ac:link>

Regards,
Radek 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events