You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
If you have always wanted to post a comment via API but find it tedious to get the right format to @mention users on cloud well the wait is over or rather I should say, the way has been there all these while.
API has always been the key to automating certain aspect of the Atlassian suite whether you're using it for a small or large team. And with Atlassian moving towards a cloud first initiative, the cloud infrastructure will only get better over the years and I'm very excited about the future features that will spring up.
Okay let's go back to this article's title "posting and mentioning a user via API" sounds intriguing doesn't it, but how would you do it? The answer to that is going through the Atlassian docs and sourcing the right endpoint to use for adding comments. However processing the other part for mentioning a user will take its toll from other endpoints.
The example I'm showing below uses a package called jiraone which is a python package that can be download by using pip install jiraone.
from jiraone import LOGIN, USER, comment user = "email" password = "token" link = "https://yourinstance.atlassian.net" LOGIN(user=user, password=password, url=link) key = "COM-42" name = "Prince Nyeche,Prince" text = """ <user> please can you help to check the docker environment? Ping <user> to help out. """
comment(key, method="post", text_block=text, placer="<user>", mention=USER.mention_user(name), event=True, visible="Users")
The name of users separated by comma, will be changed dynamically within the method with the mention keyword argument. Using the event=True
argument enables the comment endpoint to actually post the text_block. placer="<user>" is a placeholder used to change the text string, it takes the names of the user and does a search and returns an acceptable format for mentioning users within the text string. visible="Users" enables you to use the comment visibility feature and restrict the comment to certain users, standard permission for that applies.End result is you have your comment posted on Jira.
Prince Nyeche
1 comment