Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,362,526
Community Members
 
Community Events
168
Community Groups

Posting and mentioning a user via API

comment.png

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.

 

1 comment

M Amine Community Leader Jun 09, 2021


Good information

Comment

Log in or Sign up to comment
TAGS

Atlassian Community Events