IBM API Connect Integration

IBM API Connect is an API operational platform that allows developers to create, run, manage and secure APIs in IBM Cloud. SwaggerHub integrates with IBM API Connect, so you can easily deploy and synchronize your API definitions on SwaggerHub with definitions in IBM Cloud.

Video tutorial

 

Supported OpenAPI versions

The IBM API Connect integration supports only OpenAPI 2.0 definitions and has the following requirements for API definitions:

  • schemes must be set to use https only.

  • If an API uses an API key sent in: header, the key name must be either X-IBM-Client-Id or X-IBM-Client-Secret.

Considerations

  • SwaggerHub On-Premise users need v. 1.27 or later to use the IBM API Connect integration.

  • Only the Cloud version of IBM API Connect is supported.

  • You need an IBM Cloud account. You can sign up for a trial here.

  • You must have an organization, space, and service instance configured in IBM Cloud.

  • IBM API Connect integration works only in one direction – from SwaggerHub to IBM API Connect. Any changes made to the API definition in IBM API Connect will not be reflected in SwaggerHub and will be overwritten.

  • IBM integration currently supports only the "us-south" region.

IBM extensions for OpenAPI specifications

IBM API Connect uses the x-ibm-configuration extension to store API configuration parameters specific to API Connect, such as the URL of the backend server to proxy the requests to. If you already have an API definition configured in IBM API Connect, simply import this definition to SwaggerHub to preserve the configuration.

You can also add these extensions yourself. For example, if you want to use IBM API Connect as a proxy for the existing API server, say, https://pokemons.mybluemix.net, you would use something like:

host: $(catalog.host)
x-ibm-configuration:
  phase: realized
  testable: true
  enforced: true
  cors:
    enabled: true
  assembly:
    execute:
      - invoke:
          title: invoke
          target-url: https://pokemons.mybluemix.net$(request.path)
          verb: keep
          description: Invoking the backend service

For a description of the x-ibm-configuration object properties, see IBM extensions to the OpenAPI specification.

Generate an IBM API key

SwaggerHub needs an API key to connect to the IBM API Connect platform. To generate the API key:

  1. Log in to https://cloud.ibm.com/iam/apikeys.

  2. Select IBM Cloud API keys on the left and click Create an IBM Cloud API key.

    IBM Cloud API keys

    Click the image to enlarge it.

  3. Enter the name and description for this API key and click Create.

    Create API key

    Click the image to enlarge it.

  4. Click Show, and then copy the generated API key, or download it to your computer. You will not see this key later on the IBM site.

    Generated API key

    Click the image to enlarge it.

Configure the IBM API Connect integration

To set up or change IBM API Connect integration, you must be the API owner or a collaborator with the Editor role.

  1. Open the API page in SwaggerHub.

  2. If the API has several versions, select the version you want to push to IBM API Connect.

    Selecting an API version
  3. If this version is publishedPublishing an API, unpublish it. Only unpublished APIs can be integrated with IBM API Connect.

  4. Click the API name, switch to the Integrations tab, and click Add New Integrations.

    Add New Integration menu command
  5. Select IBM API Connect from the list of integrations.

  6. Configure the integration (all the fields are required):

    • Name – The display name of the integration.

    • IBM Cloud API Key – The API key you generated earlier. Click Authenticate to display the rest of the options.

    • Organization Name – The organization and space within your IBM Cloud account to which you want to deploy your API.

    • API ID – Select the name of an existing API to publish to (it will be overwritten), or select <Create New API> to create a new API in API Connect.

    • Enabled – Select this check box in order for the integration to work. Unselect it to disable the integration temporarily.

  7. Click Create and Execute, then Done.

SwaggerHub will push your API definition to the specified API in API Connect, or create a new one. From now on, every time you save your API definition on SwaggerHub, the corresponding API definition in IBM API Connect will be updated. The name of the connected API is stored in the x-ibm-name key on the root level of your API definition.

View your API in IBM API Connect

You can view your API in the Drafts section of the IBM Cloud console:

  1. Log in to https://cloud.ibm.com/apis/services.

  2. Click your service instance.

  3. On the left, click >> and select Drafts.

    Navigate to
  4. Switch to the APIs tab.

    APIs

    Click the image to enlarge it.

  5. Click the API in the list to open it in IBM API Connect’s API designer.

    API Designer

    Click the image to enlarge it.

Publish your API

A draft API is not yet available to anyone. To publish it, you need to add the API to a product (a group of APIs packaged together), then stage and publish this product to a catalog (a staging target). To do that:

  1. In the API designer, click ··· in the top right corner and select Generate a default product.

    Generate a default product
  2. Specify the product title, name and version. Select the check box to Publish this product to a catalog and select the catalog to publish to. You should have the default catalog named Sandbox.

    New product

    Click the image to enlarge it.

    Note

    The option to publish the product to a catalog is not visible if you do not have any catalogs. To create a catalog, click >>, select Dashboard, then use the Add command.

  3. Click Create product.

    Tip

    If you get the error “Product needs to provide both title and version.”, change the version format from 1.0 to another format such as 1.0.0, 1.0-beta, beta, or similar.

  4. You should see a success message informing you that the product has been published to the catalog.

    Success message

    Click the image to enlarge it.

Your API is now available for external use. See Testing API Calls below for details.

Republish after changing the API

Once a product is published, every time you update the API definition, you must re-publish the product to reflect the changes in the catalog. To do that:

  1. On the left, click >> and select Drafts.

  2. Switch to the Products tab.

  3. Click the product that contains your API.

  4. In the top right corner, click the cloud icon and select the catalog. This will stage the product to this catalog.

    Stage a product to a catalog
  5. Click >> again and select Dashboard to view your catalogs.

  6. Click the catalog.

  7. In the product list, click ··· next to your product and select Publish.

    Publish a product to a catalog

    Click the image to enlarge it.

Test API calls

To test API calls, you need to know the base URL of the catalog to which the API is published. You can find it in the catalog settings:

  1. On the left, click >> and select Dashboard.

  2. Click your catalog in the list.

  3. Switch to the Settings tab.

  4. On the left, select Gateways.

  5. Note down the base URL. It has the following format:

    https://api.{region}.apiconnect.ibmcloud.com/{org}-{space}/{catalog-name}

    Base URL of a catalog

    Click the image to enlarge it.

You can test the GET methods directly in the browser by pasting this URL to the browser address bar and appending the basePath and resource path at the end:

https://api.{region}.apiconnect.ibmcloud.com/{org}-{space}/{catalog-name}/api/pokemons/1

JSON response in the browser

Click the image to enlarge it.

You can also use the Explore tool in IBM API Connect to test all API operations in the catalog. To access this tool, click Explore and select the catalog name.

Explore a catalog

This opens interactive API documentation similar to the one you have in SwaggerHub. Select an operation on the left, specify parameters (if any) and click Call operation.

Testing operations using Explore tool

Click the image to enlarge it.

Troubleshooting

Error: "Unable to update API. If it was deleted, please remove the `x-ibm-name` extension and re-save your Swagger Definition."

This error can happen in the following cases:

  • The associated API was not found in IBM API Connect. For example, it could be deleted or its name (the Info.Name attribute in IBM API Designer) was changed. To resolve the issue:

    1. Delete the integration.

    2. Delete the x-ibm-name key from your API definition and save the changes.

    3. Add the IBM API Connect integration again and specify whether to create a new API in IBM Cloud or to connect to an existing API.

  • The IBM API key used by the integration was revoked. To resolve the issue:

    1. Generate a new IBM API key.

    2. Open the integration settings in SwaggerHub.

    3. Paste the new key and click Authenticate.

    4. Click Save and Execute.

See Also

Publication date: