Create Developer Apps, Keys in bulk and Approve them

Not applicable

I have requirment where I need to generate 100s of Developer Apps and Consumer Keys. Is there a easy way to do this ?

I am running On Premises Edge Installtion.

Solved Solved
1 12 409
1 ACCEPTED SOLUTION

adas
Participant V

Here's an example:

POST http://${management.ip}:8080/v1/o/{org-id}/developers



POST BODY:
<Developer>
  <Email>dev+${cnt}@apigee.com</Email>
  <FirstName>FName_${cnt}</FirstName>
  <LastName>LName_${cnt}</LastName>
  <UserName>dev+${cnt}</UserName>
  <Attributes>
        <Attribute>
           <Name>company</Name>
           <Value>Apigee</Value>
        </Attribute>
    </Attributes>
</Developer>

You can run this in a loop and where ${cnt} is the variable reference for the loop counter. Similarly you can create apps for the above developers:

POST http://${management.ip}:8080/v1/o/{org-id}/developers/dev+${cnt}@apigee.com/apps
<App name="app1-${cnt}">
<AccessType>read</AccessType>
<CallbackUrl>http://example.com</CallbackUrl>
<ApiProducts>
<ApiProduct>apiproduct-1</ApiProduct>
</ApiProducts>
</App>

You need to make sure that you have apiproduct-1 already created.

View solution in original post

12 REPLIES 12

Former Community Member
Not applicable

Yes you can do it. It has to be a combination of using our management APIs & a script that will invoke the API for every developer app that needs to be created.

Is there way you can share one example, specially the "request body"

adas
Participant V

Here's an example:

POST http://${management.ip}:8080/v1/o/{org-id}/developers



POST BODY:
<Developer>
  <Email>dev+${cnt}@apigee.com</Email>
  <FirstName>FName_${cnt}</FirstName>
  <LastName>LName_${cnt}</LastName>
  <UserName>dev+${cnt}</UserName>
  <Attributes>
        <Attribute>
           <Name>company</Name>
           <Value>Apigee</Value>
        </Attribute>
    </Attributes>
</Developer>

You can run this in a loop and where ${cnt} is the variable reference for the loop counter. Similarly you can create apps for the above developers:

POST http://${management.ip}:8080/v1/o/{org-id}/developers/dev+${cnt}@apigee.com/apps
<App name="app1-${cnt}">
<AccessType>read</AccessType>
<CallbackUrl>http://example.com</CallbackUrl>
<ApiProducts>
<ApiProduct>apiproduct-1</ApiProduct>
</ApiProducts>
</App>

You need to make sure that you have apiproduct-1 already created.

Hey Thanks for the example. This helps a lot.

Please advise if there is possibility to generate multiple keys for a single developer app. Say I need 200 keys for one single app.

Please advise.

Hi @Satyajit Roy Choudhury,

If you don't mind, could you let us know your use-case? It is possible to have more than 1 key for a given developer app, but that is the exception rather than the norm. You may end up losing information in the process (e.g., are those keys all really being used by 1 developer app and 1 developer? Could we benefit more from having separate keys for separate use-cases?). That's something we'd rather avoid so you get the most value out of Analytics.

Best,

-Alex

Thanks for the response @Alex Koo. Here is what we are trying to achieve:

We are going to have an event where we will have couple of 100s users accessing our APIs. My thinking was instead of creating 100s of apps and corresponding consumer keys. We can create just one apps and have couple of hundred keys associated with that.

That way we don't get into the pain of creating so many developer apps. Also this is not something we are willing to keep it for long. This is short term project we are doing. Please advise if you thing there is better way to do this ?

I would think, even in a temporary situation, you would want to separate the (app) developers. (App developers are what I think you meant when you said "users"). This way you can keep tabs on who is using your APIs the most, understand which developer apps are using which APIs, see the contact email of a developer app (right from analytics!), see if any developer apps are causing a lot of errors-- and that's just the tip of the iceberg. I get that this is a temporary solution, but imagine if your API backend is getting hammered -- it is more work to see the API key, see who it maps to, and get their contact information. If you separate your developers and their apps, this could all be readily available in Analytics reports in a few clicks.

Separating your developers is a good pattern to explore and set forth early on so this will be all familiar when you go live with a setup in prod.

You can still script the creation of apps and developers so it's not a painful process. I would not advise to lump all developers into 1 app and 1 developer, as you are losing information in the process (or you will have to maintain it somewhere else).

Make sense to me @Alex Koo. Here are couple of request if you be kinda enough to share:

  1. We really don't want to create 300 developers but I think we group them, say 5 developers in one group (means one developer app) and have one corresponding keys associated with it.
    1. Thoughts.... ?
  2. Throttling what are the ways to throttle requests
    1. Based on keys ?
    2. Based on apps ?
    3. combination of keys and apps ?
  3. Can you please share some scripts to achieve the what I am thinking
  4. What the ways to alter our outgoing response for example we want to remove some fields from out json output. Is that possible via javascript ?

Please Advise.

1) I say go all the way-- 1 app and 1 developer account for each. Your reports will be that much more meaningful, and the developer/app load will be simpler. You can read straight from a spreadsheet.

2) XFF header is a popular approach, or if you have a better way to achieve true client IP, that is the way to go. If you throttle based on key/app, you make everyone on an app suffer because of 1 bad agent.

3) We can take this off-line.

4) This is certainly possible (and easy) with JS. An alternative is you can use ExtractVariable policy to pull on the values you need, then recreate a new response, using AssignMessage policy, to your liking.

Best,

-Alex

Hello @Alex Koo, Please let me know if you share some scripts. As you mentioned to go with One Developer + One Developer App + One Consumer Key combo and we can read values from files.

Also if you can share some JS script where we can modify the response [Which is an JSON output]. What we are actually looking at to remove some values from JSON output.

1) I don't have a script on-hand, but all you would do is call the appropriate APIs to the MS to create the developer, developer apps, and import keys. The APIs you will need are located in https://github.com/apigee/apigee-management-api-po... It's just a matter of stringing the appropriate APIs together appropriately.

2) As for deleting parts of JSON, do "var jsonVar = JSON.parse(jsonResponse);" to parse the string as JSON. Then do "delete jsonVar.test.key" to delete key. Example of this can be found here.

adas
Participant V

The app update call should do it. All you need to do, is to make the PUT call with the same apiproduct, that already exists in the app. Every time you call the update API, it would add a new key, as long as the apiproduct is specified in the payload:

https://api.enterprise.apigee.com/v1/organizations/{org}/developers/{developer}/apps/{app_name}

Content-Type:
application/xml or text/xml

Request Body:
<App name='MyTestApp'>
	<AccessType>read</AccessType>
	<CallbackUrl>www.apigee.com</CallbackUrl>
          <KeyExpiresIn>1000000</KeyExpiresIn> <!-- To be added only if new key is being generated, that is if an ApiProduct is specified during an update -->
	<ApiProducts>
		<ApiProduct>{APIPRODUCT_NAME}</ApiProduct>
                 <!-- One or more ApiProducts -->
	</ApiProducts>
	<Attributes>
		<Attribute>
			<Name>foo</Name>
			<Value>bar</Value>
		</Attribute>
	</Attributes>
          <Scopes>
                 <Scope>READ</Scope>
                 <Scope>WRITE</Scope>
          </Scopes>
</App>

You can call the UPDATE api in a loop, if you want to create "x" number of apikeys for the same app/apiproduct combination.