There have been a few occasions in the past where keys have been accidentally deleted and there has been a requirement to recreate the same keys to restore traffic. In other cases, the requirement was to create a product with a specific API key which was used in a legacy system.
Following is the API call that will allow creating a custom key and adding it to the desired product:
curl -v -n -X POST \ https://api.enterprise.apigee.com/v1/o/{Org}/developers/{Developer}/apps/{App}/keys/create \ -H "Content-type: application/xml" \ -d @text.xml
Where the contents of text.xml would be :
<CredentialRequest> <Attributes/> <ConsumerKey>key</ConsumerKey> <ConsumerSecret>secret</ConsumerSecret> <ApiProducts> <ApiProduct>product</ApiProduct> </ApiProducts> <Scopes/> </CredentialRequest>
Note: The UI would continue to show the default key that was assigned when the product was added to the App. If you remove and add the product back to the App, you will notice the updated key reflected in the UI.
@Arun Kumar I tried your solution, but the key is added to an empty product:
{ "apiProducts": [], "attributes": [], "consumerKey": "IwAWRqaIG9uA4fq3PEBfher3QbZY1bbG", "consumerSecret": "IRwhKr4CiCqGNbVF", "expiresAt": -1, "issuedAt": 1435654188772, "scopes": [], "status": "approved" }
Anybody has an idea what I am doing wrong here?
It seems to work when I make another call to "manually" add the API key to my Product:
curl -v -u admin@apigee.com -k https://api.enterprise.apigee.com/v1/organizations/{org_name}/developers/{developer_email}/apps/{app... -H "Content-Type: application/json" -d '{"apiProducts": ["MyAPIProduct"], "attributes" : []}'
Any chance you can clarify the above in light of the information below?
JSON payload request for create consumer key :
{ "apiProducts" : [ "production" ], "attributes" : [ { "name" : "prop101", "value" : "val101" } ], "consumerKey" : "KEY_VALUE", "consumerSecret" : "SECRET_VALUE" }
JSON Payload request to create consumer key:
{ "apiProducts" : [ "production" ], "attributes" : [ { "name" : "prop101", "value" : "val101" } ], "consumerKey" : "KEY_VALUE", "consumerSecret" : "SECRET_VALUE" }
JSON Payload request to update consumer key with apiproduct:
{ "apiProducts" : [ "production" ], "consumerKey" : "KEY_VALUE" }
If company is subscribed to app instead of developer subscribed to app you can use following API to create desired key and secret.
curl -v -n -u adminEmail:password -X POST \ https://api.enterprise.apigee.com/v1/o/{Org}/companies/{Company-Name}/apps/{App}/keys/create \-H "Content-type: application/xml" \ -d @text.xml
Content of text.xml would be same.
Once desired key and secret are in place and if there is need to revoke or remove old keys then that can be done using management UI.
Hi @Floyd Jones, Could you follow this up in the Apigee Docs?
It seems that the API:
https://api.enterprise.apigee.com/v1/o/{Org}/companies/{Company-Name}/apps/{App}/keys/create
is missing from POST methods on:
https://apidocs.apigee.com/api/company-app-keys-0
Thanks,
Toshi
I am constantly getting 500 for following call. Any idea what i'm doing wrong?
curl -H 'Content-type:application/json' -u <email>:<password> https://api.enterprise.apigee.com/v1/organizations/{org}/developers/{dev-email}/apps/MyApp/keys/create -X POST -d \
'{
"consumerKey": "322334-232-3434-23-121121212",
"consumerSecret": "secret42010A111222",
"apiProducts": ["MyProduct"],
"attributes" : []
}'
hi @sajjad-zin
I'm just seeing your comment/question now. In the future, please ask a new question. I try to keep up on community activity, but I don't watch 5-year old old questions for new comments or sub-questions on them.
May I ask if there is a library to generate consumerKey / consumerSecret in the same way as Apigee does it? Or maybe this is well known algorithm?
The algorithm that is used is not published.
There is no library that is exposed that you can try.
What is the reason for your request? Why would you need what you are asking for? Maybe explain a little of the background for your request, and we might be able to help.