We already have an application where our users purchase other products. We want to be able to sell them API access from within the application. The sale and billing will be handled by this application but it's not connected to API usage. If they purchase the subscription they can use the API. We'd like to create accounts for the developers to sign up in to the developer portal and/or Apigee automatically so they can go in and access their oauth information etc. (the other option is to just show it in our app where they buy it but we'd still like to save them a step of having to register more than once). Is this something that's doable?
Solved! Go to Solution.
Hi @Lucian Hontau ,
Yes, there is a way to programmatically create developer accounts in the developer portal.
The Apigee Edge developer portal is built on Drupal, which is an open-source CMS framework. There are many many add-ons for drupal, packaged as "modules", which are contributed by the community. a pair of these modules allows you to expose Drupal capabilities via REST services; they are: Services, and REST Server. This means you could do the basic Create, read, Update, Delete operations on any entity managed by Drupal, including users, blog posts, forum topics, taxonomy terms, and so on.
The standard release of the Apigee Edge developer portal includes the modules necessary to do this, but by default these modules are not configured . (And sometimes they are not even enabled ). They're in the box, just not properly "turned on" if you know what I mean.
Here's how to turn them on. It takes about 3 minutes.
You can now invoke REST APIs on Drupal that will create users, create / update posts, etc.
The next thing you will ask is, "OK, now that there is a REST endpoint enabled for Drupal, what's the REST API call to make, to create a user?" This means we can now return to your original question!
The answer to that is a bit longer. The reason is that there are some pre-requisites for authentication. But the good news is that I have explained all of this in a set of blog posts elsewhere - start HERE.
The short summary is: Your app must login, then use the Cookie and CSRF token in the login response in subsequent API calls.
Login:
curl -i -X POST -H content-type:application/json \ -H Accept:application/json \ http://example.com/rest/user/login \ -d '{ "username" : "YOURUSERNAME", "password" : "YOURPASSWORD" }'
The response is like this:
{ "sessid": "ShBy6ue5TTabcdefg", "session_name": "SESS02caabc123", "token": "w98sdb9udjiskdjs", "user": { .... } }
Subsequent calls must pass wither the Cookie header, or the Cookie header as well as the X-CSRF-Token header. The former if it is a query, the latter if it is an write (create, update, or delete).
The X-CSRF-Token header must take the value that is provided for the "token" property. The cookie must take a value like "{session_name}={sessid}". In this case you would need:
Cookie:SESS02caabc123=ShBy6ue5TTabcdefg X-CSRF-Token:w98sdb9udjiskdjs
Finally, to create a user:
curl -i -X POST \ -H Cookie:SESS02caabc123=ShBy6ue5TTabcdefg \ -H X-CSRF-Token:w98sdb9udjiskdjs \ -H accept:application/json \ -H content-type:application/json \ http://example.com/rest/user -d '{ "name" : "TestUser1", "mail" : "Dchiesa+Testuser1@apigee.com", "pass": "secret123", "timezone": "America/Los_Angeles", "field_first_name": { "und": [{ "value": "Dino"}] }, "field_last_name": { "und": [{ "value": "Chiesa"}] } }'
Get more details at the linked blog posts.