If you use Apigee signin, you can automate adding an existing user to an org.
USER=person@example.com
ROLE=readonlyadmin
ORG=MYORG
curl -n -i -X POST \
-H "Content-type:application/x-www-form-urlencoded"
"$mgmtserver/v1/o/$ORG/userroles/$ROLE/users?id=$USER"
This is a documented API. If the user (email) already exists as a real user in Apigee Edge, then the new org will just appear in that user’s list of orgs.
Does this work if the user is not yet registered as an Apigee Edge user? No. The result in this case is:
{
"code" : "usersandroles.UserDoesNotExist",
"message" : "User person@example.com does not exist",
"contexts" : [ ]
}
If you want to add a new user programmatically, for Edge public cloud, you can do it, but not via the published api. The way I did it was to automate the API that is used by the UI. Like this:
curl -b "$cstr" \
[https://enterprise.apigee.com/ws/proxy/users](https://enterprise.apigee.com/ws/proxy/users)
-X POST -H content-type:application/json \
-d '{
"userRoles": ["'${ROLE}'"],
"emailId": "'${EMAIL}'",
"firstName": "'${FNAME}'",
"lastName": "'${LNAME}'"
}'
enterprise.apigee.com/ws/proxy/users is an endpoint that is used by the UI. It is not documented. It may change without notice.
“$cstr” is the browser cookie, obtained from Chrome. Invoking this request, you are making the same request the web app would make when adding a user. The cookie includes a whole bunch of information about your UI session: your own user id, and the org you’re currently signed into. How do you get that cookie?
Via a tool called cookie monster. (google it) You need to have recently signed into the apigee.com service with Chrome.
The result is: the new user will get an email from Apigee asking them to confirm their account.
This is not a supported mechanism. So if you try it, maybe it will work, and maybe it won’t. It worked for me. (Although I haven’t used it in a while) I found it by using the Chrome developer tools and sniffing the traffic.
Another way to do it would be to use something like selenium to actually automate the browser to add users. I haven’t tried that, but I’m sure it’s just a simple matter of programming.
It’s a shame that it takes so much effort to do this.
Having said all of this, don’t forget … to use SAML. Independently of “creating the user” in Apigee, be sure to set up your own IDP and configure THAT for signin.