Thanks for the solution, Nick. The API calls worked.
Original Message:
Sent: Tue September 24, 2024 04:55 AM
From: Nick Cawood
Subject: Downloading a Product/API yaml using APIc v10 ReST API
To download the yaml for an API or Product published to a Catalog (or Space - use different calls for Spaces) use these API calls:
https://apic-api.apiconnect.ibmcloud.com/v10/#/IBMAPIConnectPlatformProviderAPI_200/operation/%2Fcatalogs%2F{org}%2F{catalog}%2Fapis%2F{api-id}%2Fdocument/get
https://apic-api.apiconnect.ibmcloud.com/v10/#/IBMAPIConnectPlatformProviderAPI_200/operation/%2Fcatalogs%2F{org}%2F{catalog}%2Fproducts%2F{product-id}%2Fdocument/get
e.g. for an API (generate a bearer token "$b" and use with your platform endpoint "$url")
curl -k --request GET --header "Authorization: Bearer $b" --header 'accept: application/json' --url $url/api/catalogs/nickc-dev/sandbox/apis/70402910-bb3a-4c0a-beb4-649f41fa07e9/document
------------------------------
Nick Cawood
API Connect Consultant
IBM Expert Labs
IBM UK Ltd
https://www.linkedin.com/in/nickcawood/
Original Message:
Sent: Fri September 13, 2024 12:50 PM
From: Vijay Jethendra
Subject: Downloading a Product/API yaml using APIc v10 ReST API
Hi everyone,
Requesting your help with an issue as following. I have been to able successfully download published Product/API yamls with the use of "apic products:get" and "apic apis:get" toolkit commands. Recently, I started exploring the option of using APIc v10 ReST APIs for achieving the same result. Objective was to integrate it with a frontend that enables a wider audience to download the published Products/API yamls selectively or in bulk.
In relation to the above search, I came across a few posts from Nick Cawood which was kind of in-line with what I was trying to achieve - v10 toolkit and ReST API tips, Provider-API, API Lifecycle and Programmatic approach with v10 Provider API.
The first link seemed to fit with the use of --debug option on toolkit commands to know the ReST API toolkit commands call to service the user's request. Since "apic products:get" downloads both the Product yaml and all its associated API yaml(s), I used --debug on it to know the ReST APIs (one for Product and one for the API, as the Product I am working with has only one API) it calls that I can then call it myself. I was successful in retrieving the ReST APIs and I tried to cURL the endpoints shown in the output to download the yamls and they both return valid API responses it was meant to send (200 OK) but does not download the yamls.
I have tried a few options (using -O option on the cURL command, sending Accept header as application/octet-stream, piping the result to a file etc) to download the yamls but have been unsuccessful thus far. I am working on v10 10.0.5.
Trimmed down and masked the output of products:get, the ReST APIs it returned is as below:
curl -X 'GET' -H 'Accept: application/yaml' -H 'Accept-Language: en-us' -H 'Authorization: Bearer <the token used by toolkit>' -H 'X-Ibm-Client-Id: xxx-xxx-xxx-xxx-xxxxff2' -H 'X-Ibm-Client-Secret: xxx-xxx-xxx-xxx-xxxb0c' 'https://<APImURL>/api/catalogs/org1/dev/products/abc/1.0.0?fields=add%28product%29'
, Request dump:
GET /api/catalogs/org1/dev/products/abc/1.0.0?fields=add%28product%29 HTTP/1.1
Host: <APImURL>
User-Agent: Toolkit/a02e006974ad6470e3af5d361ca640471085c647
Accept: application/yaml
Accept-Language: en-us
Authorization: Bearer <the token used by toolkit>
X-Ibm-Client-Id: xxx-xxx-xxx-xxx-xxxxff2
X-Ibm-Client-Secret: xxx-xxx-xxx-xxx-xxxb0c
Accept-Encoding: gzip
, Request body:
2024/09/13 17:25:02 Response dump:
HTTP/1.1 200 OK
Content-Length: 4520
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: <APImURL>
Content-Security-Policy: frame-ancestors 'self'
Content-Type: application/yaml; charset=utf-8
Date: Fri, 13 Sep 2024 11:55:03 GMT
Set-Cookie: c4a71712dc0bd696917ea911dbe0b739=37cf8037267af919541371166fa99884; path=/; HttpOnly; Secure; SameSite=None
Vary: Origin
X-Content-Type-Options: nosniff
X-Request-Id: 2813a840917094c4f05b6aabd36b9da2
X-Xss-Protection: 1; mode=block
curl -X 'GET' -H 'Accept: application/yaml' -H 'Accept-Language: en-us' -H 'Authorization: Bearer <the token used by toolkit>' -H 'X-Ibm-Client-Id: xxx-xxx-xxx-xxx-xxxxff2' -H 'X-Ibm-Client-Secret: xxx-xxx-xxx-xxx-xxxb0c' 'https://<APImURL>/api/catalogs/ec74cf22-ae5c-418e-bb5b-bdbdddb56bfd/8e5c985a-3309-4885-8ffe-ee054e3405bd/apis/6df2d8b4-d6d0-48f6-8848-d9313077c2e8?fields=add%28api%2Cwsdl%29'
, Request dump:
GET /api/catalogs/ec74cf22-ae5c-418e-bb5b-bdbdddb56bfd/8e5c985a-3309-4885-8ffe-ee054e3405bd/apis/6df2d8b4-d6d0-48f6-8848-d9313077c2e8?fields=add%28api%2Cwsdl%29 HTTP/1.1
Host: <APImURL>
User-Agent: Toolkit/a02e006974ad6470e3af5d361ca640471085c647
Accept: application/yaml
Accept-Language: en-us
Authorization: Bearer <the token used by toolkit>
X-Ibm-Client-Id: xxx-xxx-xxx-xxx-xxxxff2
X-Ibm-Client-Secret: xxx-xxx-xxx-xxx-xxxb0c
Accept-Encoding: gzip
, Request body:
2024/09/13 17:25:04 Response dump:
HTTP/1.1 200 OK
Content-Length: 17678
Content-Type: application/yaml; charset=utf-8
Date: Fri, 13 Sep 2024 11:55:04 GMT
Set-Cookie: 91db42c98b4e43aef70e8712d49afca0=830881a14c38a0e23a5890e01f62c45e; path=/; HttpOnly; Secure; SameSite=None
X-Request-Id: 2cf36c98e474513e1584a42f007bb6f2
------------------------------
Thanks,
Vijay M J
------------------------------