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

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

How to add user to project role using jira rest api and json format to be used

HI ,

 

Im trying to add user to a specific project role in a project by using JIRA rest api and invoking it throw a power shell ,but when i'm passing json data as below , its giving me "Remote server returned error:400 bad request" error.

 

 Invoke Rest-Method -Uri  "https://jira url/jira/rest/api/2/project/project id/role/ role id" -Method post -Headers $Headers -Body $data1 -ContentType  "application/json"

 

Json data

$data= @"

{

"user" : ["userid/name"]

}

"@

$data1= $data | ConvertTo-Json

 

and please let me know whether i have to use PUT/POST functionality to add user to project role and its helpful if any code need to be added to Json .

2 answers

Hey Madhuri,

This should work for you

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

curl command.PNG

Using Node.js

//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);

}

request(options, callback);

Hope this helps

Reference threads and this one

Cheers

Chander

The curl command worked for me for setting the project role. How would you unselect a role?

How can I get a list of project role ids in this case?

0 votes

Hello, I have a scenario from my user . Situation is he wants around 100 users to be added to around 20 projects and assigned to multiple project roles. Can you suggest through curl example. From my end. we are not creating new groups due to our maintenance issues in jira. Without groups. is it possible through rest api from curl to achive this. Summarizinfg again. Adding m,ultople users to multiple project roles for around 20 projects. Please suggest/.

Suggest an answer

Log in or Sign up to answer
TAGS

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