How to Add actors to project using REST API (curl)

Gowri June 22, 2021

Hello, 

I would greatly appreciate if anyone could help me figure out how to add actors to a project. Do we need to create different roles for each project ?

 

I tried this  : 

End point: url+ rest/api/3/project/10007/role/10013

Content:

{
"actors": [
{
"accountId" : "6091b9e70bXyyyzzzz" //with a valid ID
}
]
}

Have proper valied header values and authentication set.

 

Regards,

Gowri

 

1 answer

1 accepted

1 vote
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 24, 2021

Hi,

I see that you are wanting to add actors to a project role using the REST API.  To answer your question, you do not need to create new roles for each project, as by default each project will have a few different roles such as "Administrators" and "Developers".  Typically you can just choose one of those roles, unless you need some more level of granular controls for users.  In which case, then it might be better to create a new role.

Once you have created the roles you want, then I suggest to find the correct ID of that role for that project, you can obtain that by calling the endpoint GET /rest/api/3/project/{projectIdOrKey}/role.  This can show you in the json payload which ID corresponds to which role.

To add an actor to an existing role (without removing all the others), use the endpoint POST /rest/api/3/project/{projectIdOrKey}/role/{id} 

you could also use the endpoint of PUT /rest/api/3/project/{projectIdOrKey}/role/{id} but please understand that if you use the PUT verb here, it sets that project role with your payload, thereby overwriting all other previously set values for that project role.

 

So if you want to just add a new actor, you need to use the POST endpoint here.  There is a curl example on that POST endpoint that shows how to add a group to a specific role:

curl --request POST \
--url 'https://your-domain.atlassian.net/rest/api/3/project/{projectIdOrKey}/role/{id}' \
--header 'Authorization: Basic [redacted]' \
--header
'Accept: application/json' \
--header
'Content-Type: application/json' \
--data
'{
"group": [ "jira-developers" ]
}'

and it also explains that you can use the "user" array if your object is not a group.  So your call in curl might look something like this:

curl --request POST \
--url 'https://your-domain.atlassian.net/rest/api/3/project/{projectIdOrKey}/role/{id}' \
--header 'Authorization: Basic [redacted]' \
--header
'Accept: application/json' \
--header
'Content-Type: application/json' \
--data
'{
"user": [ "6091b9e70bXyyyzzzz" ]
}'

Which will add that user to that project role without removing all other users from the the role.

Does that help?  Let me know if you run into any problems with this.

Andy

Gowri June 24, 2021

You are awesome Andy...!! Thanks for such detailed explanation. 

Suggest an answer

Log in or Sign up to answer