I am having trouble adding new users to the project. Is it better to add users using their id or usernames? Below is my code:
If you use the API to add users, you are required to use ID's.
Cloud doesn't offer the option to use email address or user names as this is due to security.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Nawar Noorudeen
In list of users what exactly are you using, emails or ids?
According to REST API documentation, you must use user IDs.
Also, I don't see in documentation way to add list of users. You must add them one-by-one.
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-project-role-actors/#api-rest-api-3-project-projectidorkey-role-id-post
Try to add one more loop, that will iterate through ids. Something like:
users = ["id1","id2","id3"]
for user_id in users:
users_payload = {
"user": user_id
}
...
...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to add one user at the moment to make this thing work. Is there any specific way to add the user id?
I am passing it like this:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is my working code:
def add_role_actor(projectkey, userid, roleid):
url = f"{jira_api_url}/project/{projectkey}/role/{roleid}"
payload = json.dumps({
"user": [
userid
]
})
response = requests.post(url, headers = headers, data = payload)
if response.status_code == 200:
logger.info(f"User added to project: {projectkey}")
I suppose, you have error, because you don't make json.dumps for array with user data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Evgenii Thank you for your help! I made some changes in my code and is working now! I really appreciate your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.