Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

User mention Macro - REST API

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

2 votes
Bill Bailey Community Leader Mar 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

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 Community Leader Mar 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.

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 Community Leader Jan 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.

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? 

0 votes
Radek Janata Community Leader Nov 07, 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
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

480 views 24 9
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you