Publish your APIs

Publish APIs to your portal to make them available for consumption by app developers, as described in the following sections.

Overview of API publishing

The process of publishing APIs to your portal is a two-step process:

  1. Select the API product that you want to publish to your portal.
  2. Auto-generate API reference documentation from a snapshot of your OpenAPI Specification to enable app developers to learn about your APIs. (For more information about snapshots, see What is a snapshot of an OpenAPI Specification?

When you publish an API to your portal, the following updates are made to your portal automatically:

  • SmartDocs API reference documentation is added to your portal
    The SmartDocs API reference documentation is auto-generated from a snapshot of your OpenAPI Specification. The SmartDocs UI is based on angular material, a state-of-the-art UI components library.

    Developers can review your SmartDocs API reference documentation and use the Try this API panel to make an API request and view the output. Try this API works with unsecured endpoints or secured endpoints using Basic, API Key, or OAuth Authentication, based on the security method defined in your OpenAPI Specification. For OAuth, the following flows are supported: authorization code, implicit, password, and client credentials.

    Note: You cannot edit the contents of this page directly; it does not appear in the list of pages in your portal.

    Click to expand the Try this API panel. The expanded panel enables you to view the curl call and HTTP request information, as shown below.

  • A link to the API Reference page is added to the APIs page
    The APIs page (included with the sample portal) provides a list of all APIs published to your portal with links to the respective API reference documentation for more information. You can customize the image displayed for each API card.

    Note: You cannot edit the contents of this page directly; it does not appear in the list of pages in your portal. You can edit the styling of the page when customizing your theme.

What is a snapshot of an OpenAPI Specification?

Each OpenAPI Specification serves as the source of truth throughout the lifecycle of an API. The same specification is used at each phase in the API lifecycle, from development to publishing to monitoring. When you modify a specification, you need to be cognizant of the impact the changes have on your API through other lifecycle phases, as described in What happens if I modify a specification?

When you publish your API, you take a snapshot of the OpenAPI Specification to generate API reference documentation. That snapshot represents a specific version of the specification in the spec store. If you modify the OpenAPI Specification using the spec editor, you may decide to take another snapshot of the specification in order to reflect the latest changes in the API reference documentation.

Add CORS support to your API proxies

Before publishing your APIs, you'll need to add CORS support to your API proxies to enforce client-side cross-origin requests.

CORS (Cross-origin resource sharing) is a standard mechanism that allows JavaScript XMLHttpRequest (XHR) calls executed in a web page to interact with resources from non-origin domains. CORS is a commonly implemented solution to the "same-origin policy" that is enforced by all browsers. For example, if you make an XHR call to the Twitter API from JavaScript code executing in your browser, the call will fail. This is because the domain serving the page to your browser is not the same as the domain serving the Twitter API. CORS provides a solution to this problem by allowing servers to "opt-in" if they wish to provide cross-origin resource sharing.

For information about adding CORS support to your API proxies before publishing the APIs, see Adding CORS support to an API proxy.

Explore the APIs page

To view the APIs published to your portal:
1. Select Publish > Portals and select your portal.
2. Click APIs on the portal home page.
Alternatively, you can select APIs in the portal drop-down menu in the top navigation bar.

The list of APIs is displayed.

API reference

As highlighted in the previous figure, the APIs page enables you to:

Add an API to your portal

To add an API to your portal:

  1. Select Publish > Portals and select your portal.
  2. Click APIs on the portal home page.
    Alternatively, you can select APIs in the portal drop-down menu in the top navigation bar.
  3. Click + API.
    The Add API Product to Portal dialog displays.
  4. On the API Product tab in the dialog, select the API product that you want to add to your portal.

  5. Click Next.

  6. Update the title of your API in the Title field.
    By default, the API product name is used.

  7. Select the source to use for the snapshot.
    Select a specification from the drop-down menu or select Choose a different spec to select or upload a new specification. Alternatively, you can select No spec and add one later after the API has been added, as described in Take a snapshot of the specification.

  8. Select the Published checkbox to publish the API to your portal. Deselect Published if you are not ready to publish the API.
    You can change the setting later, as described in Publish or unpublish an API on your portal.

  9. Under Audience, select one of the following options to manage the audience for your API by allowing access to:

    • Anonymous users to allow all users to view the page.
    • Registered users to allow only registered users to view the page.

    You can change the setting later, as described in Manage the audience for an API on your portal.

  10. Select an image to display in the API card on the APIs page.
    From the image drop-down, you can select an existing image, upload a new image, or provide the URL of an external image. You can add an image later, as described in Manage the image for an API card on your portal.

    Note: The size of the API card image is defined in the default theme as 344px x 192px. Be sure to select an image with a relative size. Alternatively, you can modify the image size for the API card, as described in Customize the appearance of the API card on the APIs page.

  11. Update the description of your API in the Description field.
    By default, the API product description is used.

  12. Click Finish.

Take a snapshot of the specification

After you publish your API, at any time you can take a new snapsot of the OpenAPI Specification to update the API reference documentation that is published on your portal.

To take a snapshot of the OpenAPI Specification:

  1. Select Publish > Portals and select your portal.
  2. Click APIs on the portal home page.
    Alternatively, you can select APIs in the portal drop-down menu in the top navigation bar.
  3. Position the cursor over the API for which you want to take a snapshot to display the actions.
  4. Click Snapshot icon.
    > Note: A message is displayed if your snapshot is current with the source specification selected.
  5. Select an existing specification from the Snapshot Source drop-down or select Choose a different spec to select or upload a new specification to use for generating documentation for the API. Alternatively, you can select No spec to remove the current specification.
  6. Click Update Snapshot (or Remove Snapshot, if you have selected No Spec).

API reference documentation is generated from the specification and added to the API Reference page.

Publish or unpublish an API on your portal

To publish or unpublish an API on your portal:

  1. Select Publish > Portals and select your portal.
  2. Click APIs on the portal home page.
    Alternatively, you can select APIs in the portal drop-down menu in the top navigation bar.
  3. Position the cursor over the API that you want to publish or unpublish.
  4. Click Settings icon.
  5. Select the Enabled checkbox to publish the API on your portal. Deselect Enabled to unpublish the API.
  6. Click Save.

Manage the audience for an API on your portal

Manage the audience for your API on your portal by allowing access to:

  • All users
  • Registered users only

To manage the audience for an API on your portal:

  1. Select Publish > Portals and select your portal.
  2. Click APIs on the portal home page.
    Alternatively, you can select APIs in the portal drop-down menu in the top navigation bar.
  3. Position the cursor over the API for which you want to take a manage the audience to display the actions.
  4. Click Settings icon.
  5. Under Audience, select one of the following options:
    • Anonymous users to allow all users to view the API product.
    • Registered users to allow only registered users to view the API product.
  6. Click Save.

Manage the image for an API card

Manage the image that appears with an API card on the APIs page by adding or changing the current image.

To manage the image for an API card:

  1. Select Publish > Portals and select your portal.
  2. Click APIs on the portal home page.
    Alternatively, you can select APIs in the portal drop-down menu in the top navigation bar.
  3. Position the cursor over the API for which you want to manage the image to display the actions.
  4. Click Settings icon.
  5. Under Image:
    • Click Remove to remove the current image.
    • Click Select to select or upload an image.
  6. Click Save.

Edit the title and description for an API

To edit the API title and description:

  1. Select Publish > Portals and select your portal.
  2. Click APIs on the portal home page.
    Alternatively, you can select APIs in the portal drop-down menu in the top navigation bar.
  3. Position the cursor over the API that you want to edit.
  4. Click Settings icon.
  5. Edit the Title and Description fields, as required.
  6. Click Save.

Remove an API from your portal

To remove an API from your portal:

  1. Select Publish > Portals and select your portal.
  2. Click APIs on the portal home page.
    Alternatively, you can select APIs in the portal drop-down menu in the top navigation bar.
  3. Position your cursor over the API in the list to display the actions menu.
  4. Click Delete.

Troubleshoot issues with your published APIs

When using Try this API, if the TypeError: Failed to fetch error is returned, consider the following possible causes and resolutions:

  • For mixed content errors, the error may be caused by a known swagger-ui issue. One possible workaround is to make sure that you specify HTTPS before HTTP in the schemes definition in your OpenAPI Specification. For example:

     schemes:
       - https
       - http
    
  • For CORS (Cross-origin resource sharing) restriction errors, ensure that CORS is supported for your API proxies. CORS is a standard mechanism that enables client-side cross-origin requests. See Adding CORS support for an API proxy. Ensure CORS in enabled in your browser, as well.