ApigeeX proxy or revision creation or update using mgmt api

Hi ,

I am trying to create new api proxy/update revision in APigeeX from rest mgmt api as per  the documentation but it returns 404 or 400 for following calls, what the right url and payload to invoke these endpoints.

1) creating api proxy not the revision:
https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.apis/create
curl -X "POST" -H "authorization: Bearer $token" -H "Content-Type: multipart/form-data" -F "file=@/Users/name/Downloads/campaigns_rev5_2022_02_05.zip" https://apigee.googleapis.com/v1/organizations/apg-org/apis?action=import&name=campaigns 

Request body: not sure why api documentation show this when it's the zip bundle thats to be uploaded as form-data/octet-stream.
as per docmentation, which doesn't make sense as this should be zip bundle: :
{
"contentType": "",
"data": "",
"extensions": [
{}
]
}


What would be the sample request url and paylaod be for octet-stream, is following correct:
curl -X "POST" -H "authorization: Bearer $token" -H "Content-Type: application/octet-stream" -F "file=@campaigns_rev5_2022_02_05.zip" https://apigee.googleapis.com/v1/organizations/apg-org/apis?action=import&name=campaigns 


2) updating the existing proxy by uploading zip
What's the sample payload for this request?
https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.apis.revisions/upda...
I tried following
a)
curl -X PUT 'https://apigee.googleapis.com/v1/organizations/apg-org/environments/qa/apis/pingstatus-v1/revisions/...' -H "authorization: Bearer $token" -H "Content-Type=application/octet-stream"
as per docmentaiton, which doesn't make sense as this should be zip bundle:
{
"contentType": "",
"data": "",
"extensions": []
}

b)

curl -X PUT 'https://apigee.googleapis.com/v1/organizations/apg-org/environments/qa/apis/pingstatus-v1/revisions/...' -H "authorization: Bearer $token" -H "Content-Type=multipart/form-data" -F "file=@pingstatus-v1_rev5_2022_02_05.zip"
c)
curl -X PUT 'https://apigee.googleapis.com/v1/organizations/apg-org/environments/qa/apis/pingstatus-v1/revisions/...' -H "authorization: Bearer $token" -H "Content-Type=application/octet-stream" -F "file=@pingstatus-v1_rev5_2022_02_05.zip"

 

Solved Solved
1 2 522
1 ACCEPTED SOLUTION

Hi macharya,

You're pretty close on your way to master this management API. 

There are two steps to get your proxy in place:

1. Import the bundle in the form of the .zip file

2. Deploy the bundle into a new revision to an environment.

This line is an example of the import operation

https://github.com/apigee/ahr/blob/37fb123bd40c6f41331722d4add2a837889d320c/bin/apigee-hybrid-deploy...

In fact, the whole file is a simple script to import/deploy a proxy so feel free to inspect and adapt it for your needs.

As for updating a proxy's bundle, keep in mind that, by design, you can update only API proxy revisions that have never been deployed. After deployment, an API proxy revision becomes immutable, even if it is undeployed. That would be a POST request. See following link for details:

https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.apis.revisions/upda...

 

 

View solution in original post

2 REPLIES 2

Hi macharya,

You're pretty close on your way to master this management API. 

There are two steps to get your proxy in place:

1. Import the bundle in the form of the .zip file

2. Deploy the bundle into a new revision to an environment.

This line is an example of the import operation

https://github.com/apigee/ahr/blob/37fb123bd40c6f41331722d4add2a837889d320c/bin/apigee-hybrid-deploy...

In fact, the whole file is a simple script to import/deploy a proxy so feel free to inspect and adapt it for your needs.

As for updating a proxy's bundle, keep in mind that, by design, you can update only API proxy revisions that have never been deployed. After deployment, an API proxy revision becomes immutable, even if it is undeployed. That would be a POST request. See following link for details:

https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.apis.revisions/upda...

 

 

Thanks so looking at your script, I realized for api creation:

1) since the url I was using was not surrounded in quotes in cmdline, it was skipping one of the query param "name=campaigns " and that was causing 400 bad request. Also I see 

2) -H "Content-Type: application/octet-stream"  also cause 400 return from mgmt server.
3)  
-H "Content-Type: multipart/form-data" is optional  and api creation work with or without this header.
4)  For api revision update , 
as per the documentation this is the url:

POST https://apigee.googleapis.com/v1/{name=organizations/*/apis/*/revisions/*}

I tried,

curl  -X "POST" -H "authorization: Bearer $token" -F "file=@campaigns_rev5_2022_02_05.zip" "https://apigee.googleapis.com/v1/organizations/apg-org/apis/campaigns/revisions/9" -H "Content-Type: multipart/form-data"
a) it return 400 , when I runt it for the latest created revision(that already exist in this case 9) saying revision already exist and is immutable with 

"status": "INVALID_ARGUMENT"


b) it return 404, when I run it for latest new revision that doesn't exist (in this case 10), saying revision

"status": "NOT_FOUND"


looking closely at documentation api  revision update  only works if revision 10 is already created beforehand and never deployed. In that case  b)  return 200, I just validated this.