How to create ProjectPermission and add TeamMemberships with Web Services API

Document ID : KB000047760
Last Modified Date : 14/02/2018
Show Technical Document Details

Summary

Below are examples of requests made via Chrome's REST client to create ProjectPermission and add TeamMemberships with WS API.

Issue

I. USING API KEY AUTHENTICATION

Note: generally this is a preferred method of authentication. It is easier to use, it does not require additional authentication with security token, and unlike security token, ApiKey is not session specific (which makes it unnecessary to manually maintain a session when POST requests are made outside of a browser, e.g. with a curl command).

1. generate ApiKey if it has not been already generated

For more details about ApiKey see:
Oauth Client and ApiKey FAQ
Confirm credentials used in a custom code after receiving 401 error

2. create projectpermission

In this example _abc123 is a placeholder for a valid ApiKey:

curl --header "zsessionid:_abc123" -H "Content-Type: application/json" -d"{\"ProjectPermission\":{\"Project\":\"/project/17465508882\",\"Role\":\"Viewer\",\"User\":\"/user/14095562577\"}}" https://rally1.rallydev.com/slm/webservice/v2.0/projectpermission/create


II. USING BASIC AUTHENTICATION AND SECURITY TOKEN
Note: this authentication method should be used in subscriptions where ApiKey is disabled, and on Sandbox where ApiKey is not supported.

At the time of creation this user /user/12868592636 was given viewer permissions to one project:

User-added image

Create project permission
?
1. get a security token:

https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize
?
method: GET

A token is returned:
?
{"OperationResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": [], "Warnings": [], "SecurityToken": "cb9473f7-....."}}

2. create projectpermission. Notice the security token appended to the request:

https://rally1.rallydev.com/slm/webservice/v2.0/projectpermission/create?key=cb9473f7-....

method: POST

payload:

{"ProjectPermission":{
"Project":{"_ref":"/project/14018981229"},
"Role":"Viewer",
"User":{"_ref":"/user/12868592636"}
}}



ContentType: application/json

Here is a screenshot from Chrome's REST client:

User-added image

and a screenshot of the result:


User-added image


It worked despite the warnings:

Warnings:?
[
3]
0: ?"Ignored JSON element ProjectPermission.Project during processing of this request."
1: ?"Ignored JSON element ProjectPermission.Role during processing of this request."
2: ?"Ignored JSON element ProjectPermission.User during processing of this request."

?
?
Verified in UI:

User-added image



Create team membership:

When both examples are demonstrated during the same session, the same security token can be used. No need to repeat step 1 from Example 1. 


2. add team memberships. Notice the security token appended to the request:


https://rally1.rallydev.com/slm/webservice/v2.0/user/12868592636/teammemberships/add?key=cb9473f7-.....

method: POST

payload:

{
"CollectionItems":[{"_ref":"/project/14686107187"},{"_ref":"/project/14686107446"}]
}

Verified success in UI:

User-added image