Export Proxy via Management API through Node JS in Zip format

Hi,

I am trying to call the export proxy management api through node js script and save in local directory

Referring to -

https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/apis/%7Bapi_name%7D/revi...

var download_proxy_call = {
       
      
 		url: "https://"+ username + ":" + password +"@api.enterprise.apigee.com/v1/organizations/test26/apis/"+proxyname+"/revisions/"+revisions_count+"?format=bundle",
        method: 'GET',
        headers: {
           
           'Content-Type': 'application/zip'

        } };

request(download_proxy_call, (err, res, body) => {

 if (err) { return console.log(err); }

 else{
  				
 				 filename="abc.zip";
 				 fs.writeFileSync(filename,body);


}

The file is created successfully but during unzip i encounter the file format exception.

"Unable to expand. error 21 is a directory"

I understand through curl we can download the zip with -o parameter as given in the reference url above and snippet below, but not sure how to save the file through api call via node js -

curl https://api.enterprise.apigee.com/v1/o/myOrg/apis/myProxy/revisions/1?format=bundle
-u myEMail:myPWord -o myProxy.zip

Thanks,

Aakash

0 2 342
2 REPLIES 2

I dunno, but I use the apigee-edge-js wrapper .

This script shows how to export an API. Here is a version that uses promises.

This is a snip that shows the basic idea and operation :

apigeeEdge.connect(options)
  .then(org =>
        org.proxies.export({name, revision})
        .then(result => {
          let fullFilename = path.join("output_directory", result.filename);
          fs.writeFileSync(fullFilename, result.buffer);
          return fullFilename;
        }))
  .then( result => console.log('exported to: ' + result) )
  .catch(e => console.log(e));