API Proxy update (ADD/UPDATE/DELETE) via Administative APIs

Not applicable

Hi Team @Anil Sagar @kris@apigee.com @Marsh Gardiner @Diego Zuluaga

For delta of API proxies, we have below possible changes in our APIs :

Addition of API Proxy

How to update API Products corresponding to newly added proxies. Is there any management API for that.

Updation of API Proxies

How to update API Proxy with new revision using API without affecting the associated products. Are there any management APIs available.

Does it affect the functionality of API Products which already has these API Proxies?

Deletion of API Proxies

How to delete the API Proxies and their corresponding association of API Products using Management APIs. Do we need to first update the API Product by removing the API Proxy and then delete that API Proxy?

Is there any management API available.

Regards,

Rajesh

Solved Solved
1 8 1,168
2 ACCEPTED SOLUTIONS

Yes, there are management APIs in Apigee Edge for every operation that you can perform on the system. The index to all the methods is here. Helpfully, the APIs are all available via smartdocs, so you can invoke the APIs directly from your browser, to test them out.

I will try to answer your specific questions as well.

1. Adding API proxies to API Products.

You use the PUT verb and pass all product attributes. Suppose your existing product has two apiproxies, as shown by this query in curl :

$ curl -n   -X GET ${mgmtserver}/v1/o/${orgname}/apiproducts/Prod1
{
  "apiResources" : [ ],
  "approvalType" : "auto",
  "attributes" : [ {
    "name" : "access",
    "value" : "public"
  } ],
  "createdAt" : 1436383882428,
  "createdBy" : "DChiesa@apigee.com",
  "description" : "",
  "displayName" : "Prod1",
  "environments" : [ "test" ],
  "lastModifiedAt" : 1440022507579,
  "lastModifiedBy" : "DChiesa@apigee.com",
  "name" : "Prod1",
  "proxies" : [ "producttest1", "tokentest" ],
  "quota" : "1000",
  "quotaInterval" : "1",
  "quotaTimeUnit" : "minute",
  "scopes" : [ "" ]
}

To add another API proxy, use this kind of command:

$ curl -n -i \
  -H "Content-Type:application/json" \
  -X PUT ${mgmtserver}/v1/o/${orgname}/apiproducts/Prod1 \
  -d '{
   "approvalType" : "auto",
   "attributes" : [ {
      "name" : "access",
      "value" : "public"
   } ],
   "displayName" : "Prod1",
   "apiResources" : [ "/**" ],
   "description" : "Testing update of product via mgmt API",
   "environments": [ "test" ],
   "proxies": [ "ytd911", "producttest1", "tokentest" ],
   "quota": "1000",
   "quotaInterval": "1",
   "quotaTimeUnit": "minute"
  }'

Upon query you should see the additional API proxy in the list:

$ curl -n   -X GET ${mgmtserver}/v1/o/${orgname}/apiproducts/Prod1
{
  "apiResources" : [ "/**" ],
  "approvalType" : "auto",
  "attributes" : [ {
    "name" : "access",
    "value" : "public"
  } ],
  "createdAt" : 1436383882428,
  "createdBy" : "DChiesa@apigee.com",
  "description" : "Testing update of product via mgmt API",
  "displayName" : "Prod1",
  "environments" : [ "test" ],
  "lastModifiedAt" : 1448301574794,
  "lastModifiedBy" : "DChiesa@apigee.com",
  "name" : "Prod1",
  "proxies" : [ "ytd911", "producttest1", "tokentest" ],
  "quota" : "1000",
  "quotaInterval" : "1",
  "quotaTimeUnit" : "minute",
  "scopes" : [ ]
}

see the documentation here.

2. Update of API Proxies

For any API Proxy, you can update specific items, or you can import and deploy entirely new API proxy bundles. You don't specify exactly which path you'd prefer. In most cases customers perform the latter, because the API Proxy configuration is stored in source code control. They'll check out the latest copy from their git repo (or other repository), zip up the contents, and then import the entire bundle as a new revision of the API proxy.

This involves multiple steps. To zip up a bundle, you should use something like this:

zip -r apiproxy.zip apiproxy -x "*/*.*~" -x "*/#*.*#" 

Then, to import the proxy as a new revision,

curl -n -X POST \
   -H "Content-Type: application/octet-stream" \
   "${mgmtserver}/v1/o/${orgname}/apis/?action=import&name=${apiname}" \
   -T apiproxy.zip

You must examine the output of this command to determine the revision of the newly-imported bundle. You can then query the deployment status of other revisions

curl -n -X GET "${mgmtserver}/v1/o/${orgname}/apis/${apiname}/deployments"

...parse the output of that, undeploy the previously deployed revisions, from any environments in which they are deployed, like so:

curl -n -X POST \
  "${mgmtserver}/v1/o/${orgname}/apis/${apiname}/revisions/${rev}/deployments?action=undeploy&env=${env}"

and then deploy the newly-imported revision:

curl -n -X POST \
  "${mgmtserver}/v1/o/${orgname}/apis/${apiname}/revisions/$rev/deployments?action=deploy&env=${environment}" 

This action will affect all API Products which contain the specific api proxies.

3. Deleting API Proxies.

To delete an API proxy, you must first remove its association from any containing API Products, using the PUT command provided in the answer to question 1, that I gave above.

Then, undeploy any revisions you wish to delete, as shown in the answer to Question 2.

Then you can delete individual revisions, like so:

curl -n -X DELETE \
   "${mgmtserver}/v1/o/${orgname}/apis/${apiproxy}/revisions/${rev}"

or delete the API Proxy and ALL its revisions, like this:

curl -n -X DELETE \
   "${mgmtserver}/v1/o/${orgname}/apis/${apiproxy}"

View solution in original post

Not applicable

Thanks @sgilson, able to resolve my queries by the fitting reply. Just want to add what we have done to achieve the goal (as our problem is little bit complex - no of products are associated with these APIs) :

Add proxies :

1. Get API Product

2. Import a new API Proxy

3. Update API Product with the new API in the list of APIs associated with the product

Update Proxies :

1. Get API Proxy (to get the latest revision i.e. max revision of api)

2. Import proxy using the below management API (It will create a new revison of API at APIGEE i.e. max revision +1 )

3. Undeploy max revision of API from all the available environment (DELETE action)

4. Deploy latest available version at APIGEE i.e. max revision +1

Delete proxies :

1. Get API Product

2. Update API Product - remove the deleted API from the list of API present in update product json.

3. Delete API proxy from apigee gateway.

View solution in original post

8 REPLIES 8

Yes, there are management APIs in Apigee Edge for every operation that you can perform on the system. The index to all the methods is here. Helpfully, the APIs are all available via smartdocs, so you can invoke the APIs directly from your browser, to test them out.

I will try to answer your specific questions as well.

1. Adding API proxies to API Products.

You use the PUT verb and pass all product attributes. Suppose your existing product has two apiproxies, as shown by this query in curl :

$ curl -n   -X GET ${mgmtserver}/v1/o/${orgname}/apiproducts/Prod1
{
  "apiResources" : [ ],
  "approvalType" : "auto",
  "attributes" : [ {
    "name" : "access",
    "value" : "public"
  } ],
  "createdAt" : 1436383882428,
  "createdBy" : "DChiesa@apigee.com",
  "description" : "",
  "displayName" : "Prod1",
  "environments" : [ "test" ],
  "lastModifiedAt" : 1440022507579,
  "lastModifiedBy" : "DChiesa@apigee.com",
  "name" : "Prod1",
  "proxies" : [ "producttest1", "tokentest" ],
  "quota" : "1000",
  "quotaInterval" : "1",
  "quotaTimeUnit" : "minute",
  "scopes" : [ "" ]
}

To add another API proxy, use this kind of command:

$ curl -n -i \
  -H "Content-Type:application/json" \
  -X PUT ${mgmtserver}/v1/o/${orgname}/apiproducts/Prod1 \
  -d '{
   "approvalType" : "auto",
   "attributes" : [ {
      "name" : "access",
      "value" : "public"
   } ],
   "displayName" : "Prod1",
   "apiResources" : [ "/**" ],
   "description" : "Testing update of product via mgmt API",
   "environments": [ "test" ],
   "proxies": [ "ytd911", "producttest1", "tokentest" ],
   "quota": "1000",
   "quotaInterval": "1",
   "quotaTimeUnit": "minute"
  }'

Upon query you should see the additional API proxy in the list:

$ curl -n   -X GET ${mgmtserver}/v1/o/${orgname}/apiproducts/Prod1
{
  "apiResources" : [ "/**" ],
  "approvalType" : "auto",
  "attributes" : [ {
    "name" : "access",
    "value" : "public"
  } ],
  "createdAt" : 1436383882428,
  "createdBy" : "DChiesa@apigee.com",
  "description" : "Testing update of product via mgmt API",
  "displayName" : "Prod1",
  "environments" : [ "test" ],
  "lastModifiedAt" : 1448301574794,
  "lastModifiedBy" : "DChiesa@apigee.com",
  "name" : "Prod1",
  "proxies" : [ "ytd911", "producttest1", "tokentest" ],
  "quota" : "1000",
  "quotaInterval" : "1",
  "quotaTimeUnit" : "minute",
  "scopes" : [ ]
}

see the documentation here.

2. Update of API Proxies

For any API Proxy, you can update specific items, or you can import and deploy entirely new API proxy bundles. You don't specify exactly which path you'd prefer. In most cases customers perform the latter, because the API Proxy configuration is stored in source code control. They'll check out the latest copy from their git repo (or other repository), zip up the contents, and then import the entire bundle as a new revision of the API proxy.

This involves multiple steps. To zip up a bundle, you should use something like this:

zip -r apiproxy.zip apiproxy -x "*/*.*~" -x "*/#*.*#" 

Then, to import the proxy as a new revision,

curl -n -X POST \
   -H "Content-Type: application/octet-stream" \
   "${mgmtserver}/v1/o/${orgname}/apis/?action=import&name=${apiname}" \
   -T apiproxy.zip

You must examine the output of this command to determine the revision of the newly-imported bundle. You can then query the deployment status of other revisions

curl -n -X GET "${mgmtserver}/v1/o/${orgname}/apis/${apiname}/deployments"

...parse the output of that, undeploy the previously deployed revisions, from any environments in which they are deployed, like so:

curl -n -X POST \
  "${mgmtserver}/v1/o/${orgname}/apis/${apiname}/revisions/${rev}/deployments?action=undeploy&env=${env}"

and then deploy the newly-imported revision:

curl -n -X POST \
  "${mgmtserver}/v1/o/${orgname}/apis/${apiname}/revisions/$rev/deployments?action=deploy&env=${environment}" 

This action will affect all API Products which contain the specific api proxies.

3. Deleting API Proxies.

To delete an API proxy, you must first remove its association from any containing API Products, using the PUT command provided in the answer to question 1, that I gave above.

Then, undeploy any revisions you wish to delete, as shown in the answer to Question 2.

Then you can delete individual revisions, like so:

curl -n -X DELETE \
   "${mgmtserver}/v1/o/${orgname}/apis/${apiproxy}/revisions/${rev}"

or delete the API Proxy and ALL its revisions, like this:

curl -n -X DELETE \
   "${mgmtserver}/v1/o/${orgname}/apis/${apiproxy}"

Thanks @Dino for the prompt reply. These management apis are quite helpful to get the job done.

Hi

Is there a Edge Management API which only updates the "proxies" attribute of the JSON received from GetAPIProduct call below

(http://apigee.com/docs/management/apis/get/organizations/%7Borg_name%7D/apiproducts/%7Bapiproduct_name%7D-0)

There is one Update API Product call which updates an existing API Product but it takes all required values again

(http://apigee.com/docs/management/apis/put/organizations/%7Borg_name%7D/apiproducts/%7Bapiproduct_name%7D)

But I need to just update the "proxies" attribute array with new API Proxies which are published and deployed on Gateway.

Any help would be much apreciated

Thanks

GUARAV, I suggest that you ask a new question, rather than asking questions in the comment stream of an existing question.

Here are the links to the docs for these APIs:

1. Adding API proxies to API Products.

2. Update of API Proxies

3. Deleting API Proxies

Not applicable

Thanks @sgilson, able to resolve my queries by the fitting reply. Just want to add what we have done to achieve the goal (as our problem is little bit complex - no of products are associated with these APIs) :

Add proxies :

1. Get API Product

2. Import a new API Proxy

3. Update API Product with the new API in the list of APIs associated with the product

Update Proxies :

1. Get API Proxy (to get the latest revision i.e. max revision of api)

2. Import proxy using the below management API (It will create a new revison of API at APIGEE i.e. max revision +1 )

3. Undeploy max revision of API from all the available environment (DELETE action)

4. Deploy latest available version at APIGEE i.e. max revision +1

Delete proxies :

1. Get API Product

2. Update API Product - remove the deleted API from the list of API present in update product json.

3. Delete API proxy from apigee gateway.

Thank you @Rajesh Lohani for sharing the end solution with community, I am sure it will be helpful for others too..