API Connect

 View Only

API Connect v10 REST API calls: Provider-API, API Lifecycle

By Nick Cawood posted Thu February 23, 2023 06:31 AM

  

Hi,

Following up on my blog about getting started using the API Connect v10 REST API calls ( here ) I thought I would share some calls around the API Lifecycle that might be of interest.

All the calls for the API Connect v10 Provider-API are described here https://apic-api.apiconnect.ibmcloud.com/v10/#/IBMAPIConnectPlatformProviderAPI_200/overview but I will list some useful calls around the API Lifecycle from the Provider-API in this blog:

Here $mgmt-url is the URL for the API Manager (you can get all you credentials from the API Manager's "Download Toolkit" tile) and $b is the Bearer Token generated based on those credentials (see my getting started blog for details).

  • Get IDs for all Draft APIs & Products from a Provider Organization in API Manager by listing all the details:

curl -v -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/orgs/{org}/drafts

  • Use those IDs to get details of specific APIs & Products from the API Manager Drafts:

curl -v -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/orgs/{org}/drafts/draft-apis/<API-ID>

curl -v -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/orgs/{org}/drafts/draft-apis/<API-ID>/document

curl -v -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/orgs/{org}/drafts/draft-products/<PRODUCT-ID>

curl -v -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/orgs/{org}/drafts/draft-products/<PRODUCT-ID>/document

  • Get all Products from a Catalog:

curl -v -k -X GET -H 'Accept: application/json' -H "Authorization: bearer $b" https://$mgmt-url/api/catalogs/{org}/{catalog}/products

  • Create a Draft API (using API yaml/json) in your API Manager Provider Organization:

curl -v -k -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/orgs/{org}/drafts/draft-apis --data-raw '{"draft_api":{"swagger":"2.0","info":{"title":"theAPI","x-ibm-name":"theapi","version":"v1.0"},"schemes":["https"],"basePath":"/theapi","security":[{"clientID":[]}],"securityDefinitions":{"clientID":{"type":"apiKey","in":"header","name":"X-IBM-Client-Id"}},"x-ibm-configuration":{"phase":"realized","testable":true,"enforced":true,"properties":{"target-url":{"value":"https://randomuser.me/api","description":"The URL of the target service","encoded":false}},"catalogs":{},"cors":{"enabled":true},"application-authentication":{"certificate":false},"assembly":{"execute":[{"invoke":{"title":"invoke","version":"2.0.0","verb":"keep","target-url":"$(target-url)"}}]},"gateway":"datapower-api-gateway","type":"rest"},"paths":{"/getTestResults":{"get":{"responses":{"200":{"description":"Success!","schema":{"type":"object"}}},"consumes":[],"produces":[]}}}}}'

  • Create a Draft Product (using API yaml/json & containing the Draft API created above) in your API Manager Provider Organization:

curl -v -k -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/orgs/{org}/drafts/draft-products --data-raw '{"draft_product":{"info":{"version":"1.0.0","title":"theProduct","name":"theproduct"},"gateways":["datapower-api-gateway"],"plans":{"default-plan":{"title":"Default Plan","description":"Default Plan","rate-limits":{"default":{"value":"100/1hour"}}}},"apis":{"theapiv1.0":{"name":"theapi:v1.0"}},"visibility":{"view":{"type":"public","orgs":[],"tags":[],"enabled":true},"subscribe":{"type":"authenticated","orgs":[],"tags":[],"enabled":true}},"product":"1.0.0"}}'

  • Publish Products to promote to different Catalogs (Dev -> Test -> Prod):

curl -v -k -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/catalogs/{org}/dev/publish-draft-product --data-raw '{"draft_product_url":"$mgmt-url/api/orgs/{org}/drafts/draft-products/{product-id}"}'

curl -v -k -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/catalogs/{org}/test/publish-draft-product --data-raw '{"draft_product_url":"$mgmt-url/api/orgs/{org}/drafts/draft-products/{product-id}"}'

curl -v -k -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: bearer $b" $mgmt-url/api/catalogs/{org}/prod/publish-draft-product --data-raw '{"draft_product_url":"$mgmt-url/api/orgs/{org}/drafts/draft-products/{product-id}"}'

  • Publish a Product, from a file, direct to the Catalog bypassing creation in Drafts (run from the same directory as the files or use absolute paths as reference):

curl -v -k -X POST $mgmt-url/api/catalogs/{org}/{catalog}/publish -H 'Accept: application/json' -H "Authorization: Bearer $b" -H "content-type: multipart/form-data" -F "product=@theproduct_1.0.0.yaml;type=application/yaml" -F "openapi=@theapi_1.0.0.yaml;type=application/yaml"

  • Publish a Product, from a file, direct to the Catalog bypassing creation in Drafts with APIs which include WSDLs:

curl -v -k -X POST $mgmt-url/api/catalogs/{org}/{catalog}/publish -H 'Accept: application/json' -H "Content-Type: multipart/form-data" -H "Authorization: Bearer $b" -F "product=@/directory/file/location/fromwsdlProduct_1.0.0.yaml;type=application/yaml" -F "openapi=@/directory/file/location/fromwsdlAPI_1.0.0.yaml;type=application/yaml" -F "wsdl=@/directory/file/location/Client-backend-system-WSDL.wsdl;type=application/wsdl"

  • Deprecate a Product (see above to get IDs):

curl -v -k -X PATCH -H 'Accept: application/json' -H 'content-type: application/json' -H "Authorization: bearer $b" -d '{"state": "deprecated"}' https://$mgmt-url/api/catalogs/{org}/{catalog}/products/<PRODUCT-ID>

  • Retire a Product (see above to get IDs):

curl -v -k -X PATCH -H 'Accept: application/json' -H 'content-type: application/json' -H "Authorization: bearer $b" -d '{"state": "retired"}' https://$mgmt-url/api/catalogs/{org}/{catalog}/products/<PRODUCT-ID>

  • Archive a Product (see above to get IDs):

curl -v -k -X PATCH -H 'Accept: application/json' -H 'content-type: application/json' -H "Authorization: bearer $b" -d '{"state": "archived"}' https://$mgmt-url/api/catalogs/{org}/{catalog}/products/<PRODUCT-ID>

  • Delete an API or Product from Drafts (see above to get IDs):

curl -v -k -X DELETE -H 'Accept: application/json' -H "Authorization: bearer $b" https://$mgmt-url/api/orgs/{org}/drafts/draft-apis/<API-ID>

curl -v -k -X DELETE -H 'Accept: application/json' -H "Authorization: bearer $b" https://$mgmt-url/api/orgs/{org}/drafts/draft-products/<PRODUCT-ID>

I hope you find this guide useful.

-------------------------------------------------
Nick Cawood
API Connect Consultant
IBM Hybrid Cloud Integration Expert Labs
IBM UK Ltd

https://www.linkedin.com/in/nickcawood/
-------------------------------------------------


#APIConnect

12 comments
134 views

Permalink

Comments

Thu June 08, 2023 11:34 AM

@Stefen Salvatore - the files:

The API code example:
swagger: '2.0'
info:
  title: theAPI
  x-ibm-name: theapi
  version: 1.0.0
schemes:
  - https
basePath: /theapi
security:
  - clientID: []
securityDefinitions:
  clientID:
    type: apiKey
    in: header
    name: X-IBM-Client-Id
x-ibm-configuration:
  phase: realized
  testable: true
  enforced: true
  properties:
    target-url:
      value: https://randomuser.me/api
      description: The URL of the target service
      encoded: false
  catalogs: {}
  cors:
    enabled: true
  application-authentication:
    certificate: false
  assembly:
    execute:
      - invoke:
          title: invoke
          version: 2.0.0
          verb: keep
          target-url: $(target-url)
  gateway: datapower-api-gateway
  type: rest
paths:
  /getTestResults:
    get:
      responses:
        '200':
          description: Success!
          schema:
            type: object
      consumes: []
      produces: []

The Product example:
info:
  version: 1.0.0
  title: theProduct
  name: theproduct
gateways:
  - datapower-api-gateway
plans:
  default-plan:
    title: Default Plan
    description: Default Plan
    rate-limits:
      default:
        value: 100/1hour
    apis:
      theapiv1.0: {}
apis:
  theapiv1.0:
    name: 'theapi:1.0.0'
visibility:
  view:
    type: public
    orgs: []
    tags: []
    enabled: true
  subscribe:
    type: authenticated
    orgs: []
    tags: []
    enabled: true
product: 1.0.0

Thu June 08, 2023 11:27 AM

@Stefen Salvatore

So I got this working for you (and I updated my post):

curl -v -k -X POST [mgmt hostname url]/api/catalogs/[org]/[catalog]/publish \
-H 'Accept: application/json' \
-H "Authorization: Bearer [your bearer token]" \
-H "content-type: multipart/form-data" \
-F "product=@theproduct_1.0.0.yaml;type=application/yaml" \
-F "openapi=@theapi_1.0.0.yaml;type=application/yaml"


Files uploaded too.

Good luck...

Thu June 08, 2023 04:55 AM

@Stefen Salvatore unfortunately I developed this syntax on 10.0.1.x and I have just retested it against 10.0.5.x and it appears that this syntax is no longer valid against 10.0.5.x

Thu June 08, 2023 01:32 AM

API Connect v10.0.5.0

Wed June 07, 2023 04:48 AM

I will look into this. I don't have a Postman license so am unable to use that tool, but this could also be an APIC version issue.

Which APIC version are you using? 

Tue June 06, 2023 01:25 AM

Hi @Nick Cawood 

Yes. I am unable to understand what actually we should pass.
Any kind of guidance/help is useful to me.

and the files.json(yamls) are which you used in blog.
getting this error:

{
    "status"400,
    "message": [
        "The product 'theproduct:1.0.0 (theProduct)' has the following API references which do not point to any APIs: 'theapiv1.0'."
    ]
}


Thanks in advance!
Vyasavardhan R

Mon June 05, 2023 11:33 AM

Vyasavardhan Ramagiri

The form data is the Open API spec for your API and the associated Product.

Are you asking for guidance on the code for those?

Mon June 05, 2023 09:30 AM

  • Publish a Product, from a file, direct to the Catalog bypassing creation in Drafts (run from the same directory as the files or use absolute paths as reference):

curl -v -k -X POST $mgmt-url/api/catalogs/{org}/{catalog}/publish -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer $b' --header 'accept: application/json' --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' --form product='file=@"theProduct.yaml"' --form openapi='file=@"theAPI.yaml"'
 what will be the actual form-data to be passed in the request?
consider iam testing it from POSTMAN.

thanks in advance!

Tue May 16, 2023 09:25 AM

Hi, to use the Consumer-API or Consumer Analytics-API you need to generate a Consumer Bearer Token. This is explained here:

https://community.ibm.com/community/user/integration/blogs/nick-cawood/2023/02/23/api-connect-v10-rest-api-calls-consumer-api-genera

Once you have that bearer token then you can call the Consumer-APIs and the Consumer Analytics-APIs.

Sun May 14, 2023 07:10 AM

Hi Nick...
 
I am trying to access the Consumer Analytics API data from toolkit CLI, to get the consumer level analytics data using the below URL, but getting '404-Page not found error'. Please advise how to get the consumer analytics data using the REST API's
 
 
https://abc.com/consumer-analytics/orgs/abcbank/apps/Samp/dashboard

Tue February 28, 2023 06:28 AM

Hi Ashok,

- Provider Org / Catalog / Space / Consumer Org membership can be managed using the Provider-API https://apic-api.apiconnect.ibmcloud.com/v10/#/IBMAPIConnectPlatformProviderAPI_200/overview

Search for "members" in the search window for the Provider-API for the DELETE calls.

- The Provider-API also manages the users in the Local User Registries, again search for "users" in the search window for the Provider-API for the DELETE calls to delete a user from the LUR.

- The Consumer Org membership API calls from the Provider-API manages Portal users.

-------------------------------------------------
Nick Cawood
API Connect Consultant
IBM Hybrid Cloud Integration Expert Labs
IBM UK Ltd

https://www.linkedin.com/in/nickcawood/
-------------------------------------------------

Tue February 28, 2023 06:05 AM

Thanks for your write up Nick. I wanted to create/update/delete users in API Manager and API Developer portal using the REST API's provided by the product. I couldn't find such API's under User Management section. Please let me know if the API's are available for this functionality. Thanks