Which API to use to to add a user to a role?

There are two APIs for adding a user to a role. In the first, you pass the role in the payload:

curl -H "Content-Type:application/xml" -u ADMIN:PWORD -X POST
https://api.enterprise.apigee.com/v1/o/ORGNAME/users/USEREMAIL/userroles/ 
-d '<Roles><Role name="ROLENAME"/></Roles>' 

In the second, you specify it in the request URL:

curl -H "Content-Type:application/x-www-form-urlencoded" -u ADMIN:PWORD -X POST 
https://api.enterprise.apigee.com/v1/o/ORGNAME/userroles/ROLENAME/users?id=USEREMAIL

Is one of these the preferred method?

Stephen

Solved Solved
0 2 259
1 ACCEPTED SOLUTION

I prefer this @Stephen Gilson,

curl -H "Content-Type:application/x-www-form-urlencoded"-u ADMIN:PWORD -X POST 
https://api.enterprise.apigee.com/v1/o/ORGNAME/userroles/ROLENAME/users?id=USEREMAIL

reason - its convenient to add users to an org who already do not exist in the org

View solution in original post

2 REPLIES 2

I prefer this @Stephen Gilson,

curl -H "Content-Type:application/x-www-form-urlencoded"-u ADMIN:PWORD -X POST 
https://api.enterprise.apigee.com/v1/o/ORGNAME/userroles/ROLENAME/users?id=USEREMAIL

reason - its convenient to add users to an org who already do not exist in the org

If you are a system admin, you can add user to a org and assign role to a user in single step :

curl -u SYSADMIN:SYSPWORD -X

POST https://api.enterprise.apigee.com/v1/users/USEREMAIL/userroles -d '{"role":[{"name":"orgadmin","organization”:"ORGNAME"}],"user":{"emailId”:"USEREMAIL","firstName”:"FirstName","lastName”:"LastName"}}