How to create a new app credential for an existing app with the Apigee API

The question came up in some recent discussions that the documentation for the generateKeyPair API method is not entirely clear how the post data should be structured to create a new credential for an existing developer app.

The answer lies in the DeveloperApp data structure - the apiProducts string array that can be optionally added, and this is used when sending a POST request to create new credentials. For example, I have a developer app in my project, and I would like to create a new credential that is subscribed to the API product deepmind_alphafold_1e3h. I can create the credential with this call:

curl -i -X POST "https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/developers/$EMAIL/apps/$APP_ID" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H 'Content-Type: application/json' \
--data-binary @- << EOF
{
  "apiProducts": [
    "deepmind_alphafold_1e3h"
  ]
}
EOF

The trick is that you just add the apiProducts array of product names to the Developer App payload, and the response will include the new credentials subscribed to the products.

OR you can just pass the apiProducts array without any other properties, as shown above, and you will also get the full DeveloperApp object with the new credentials returned.

Happy portal building!

:thought_balloon: Get in touch with a Google Cloud Sales Specialist

1 Like