Hi. My name is Paulo and i'm working on implementing some automations using Jira REST API as part of my work and studying. I'm Trying to assign an user to a project via API but I'm strugling to find a way to do that. I searched and found someting called Project Role that I can create and assign a user via API, but I couldn't find a way to associate a Project Role to a Project. Can you help me with that? Sorry for my bad english, its not my native language.
I need to find a way to manage an user to a project via API. The possibility of add and remove the user of a project. using REST API v3. Is that possible?
Thanks!
Hi @paulo_silva
curl -D- -u <username>:<password> -H "Content-Type:application/json" -X POST -d '{"user":["username"]}' -k https://jira-stg.example.com/rest/api/2/project/ABC/role/10002
//Use .defaults({strictSSL: false}) to by pass SSL certificate or https connection var request = require('request').defaults({strictSSL: false}) var headers = { 'Content-Type': 'application/json' }; var dataString = '{"user":["cinguva","apawl"]}'; var options = { url: 'https://jira-stg.gogoair.com/rest/api/2/project/PSOBAT/role/10002', method: 'POST', headers: headers, body: dataString, auth: { 'user': 'admin', 'pass': 'password' } }; function callback(error, response, body) { console.log(error); }
Hi @Vikrant Yadav. Thanks for your answer! I'm not used to that programming language yet. I'm using python to run my aplication. I'm strugling with where to place the user information to specify the user.
Should I put something like that next to the group section?
payload = json.dumps( {"user": ["user-information"]} )
# This code sample uses the 'requests' library: # http://docs.python-requests.org import requests from requests.auth import HTTPBasicAuth import json url = "https://your-domain.atlassian.com/rest/api/2/project/{projectIdOrKey}/role/{id}" auth = HTTPBasicAuth("email@example.com", "") headers = { "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps( { "group": [ "jira-developers" ] } ) response = requests.request( "POST", url, data=payload, headers=headers, auth=auth ) print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @paulo_silva ,
It should be a POST method. Kindly check this section - https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-project-role-actors/#api-group-project-role-actors
POST /rest/api/2/project/{projectIdOrKey}/role/{id}
To get the list of all project role ids - https://your-domain.atlassian.com/rest/api/2/role
Hope that helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Niranjan. Thanks for your answer! Sorry for the delay on replying to you. I'm still learning how to use api and i'm trying to run this aplication via python. My problem is to find where to add the information to specify the user.
I'm editing that python code sample that should Add actors to project role. Should I write something like that?
payload = json.dumps( {"user": ["user-information"]} )
# This code sample uses the 'requests' library: # http://docs.python-requests.org import requests from requests.auth import HTTPBasicAuth import json url = "https://your-domain.atlassian.com/rest/api/2/project/{projectIdOrKey}/role/{id}" auth = HTTPBasicAuth("email@example.com", "") headers = { "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps( { "group": [ "jira-developers" ] } ) response = requests.request( "POST", url, data=payload, headers=headers, auth=auth ) print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've got it! It is so simple that I'm kinda shamed..
I just add the 'user' inside payload just like the 'group' is and filled the others parameters just like I saw on Jira API website.
When the aplication runned it add the user to the project.
This is how I add user on payload:
payload = json.dumps( {
"group": ["jira-software-users"],
'user': ['{user-id-example}']
} )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My doubt is how to put the information on the code to assign the user to the project. I trying to use that python sample that are avaliable on Jira API in the section that "Add actors to project role", but I'm not finding where to place the user information.
Should I create another variable called payload = json.dumps( {"user": ["user-information"]} )?
# This code sample uses the 'requests' library: # http://docs.python-requests.org import requests from requests.auth import HTTPBasicAuth import json url = "https://your-domain.atlassian.com/rest/api/2/project/{projectIdOrKey}/role/{id}" auth = HTTPBasicAuth("email@example.com", "") headers = { "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps( { "group": [ "jira-developers" ] } ) response = requests.request( "POST", url, data=payload, headers=headers, auth=auth ) print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @paulo_silva ,
I hope you have solved this problem. But here is my suggestion to this
If you want to add a particular user to the project role, you can use the below example for the payload:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.