Connect API Gateway with API hub

This page describes how to connect API Gateway with Apigee API hub to allow you to view your APIs and centralize your API management.

Overview

As an API Gateway administrator, to connect API Gateway with API hub you'll need to do the following steps:

  1. Provision API hub
  2. Attach your API Gateway project to API hub

Before you begin: Grant roles

Ensure that you have the appropriate Identity and Access Management (IAM) roles to connect API Gateway with API hub.

In the project where you will provision API hub:

  • Grant roles for provisioning, as described in Before you begin in the API hub provisioning steps.

In the API Gateway projects that you will attach to API hub:

  • Grant the Cloud API hub Runtime Project Attachment Editor (roles/apihub.runTimeProjectAttachmentsEditor) role to your principal account.
  • To attach your API Gateway project to API hub using the Google Cloud console, grant the Browser (roles/browser) role to your principal account.

Provision API hub

Before you can connect API Gateway with API hub, you'll need to provision API hub in your host project. A host project is a Google Cloud project in your Google Cloud organization that you designate as the consumer project for all API hub resources. A single API hub instance can be provisioned per host project.

To provide centralized discovery of APIs across all of your API Gateways, we recommend using one dedicated host project for the API hub instance and attaching multiple API Gateway projects, referred to as runtime projects, to the API hub instance.

To provision API hub in your host project, do one of the following:

  • In the Google Cloud console, go to the API hub page, select the Google Cloud project to use as the host project, and click Set up API hub.

    You can access this page from API Gateway pages as follows:

    • Click Get started in the API hub banner at the top of any of the API Gateway pages
    • Click Get started with API hub at the top of the APIs page

    Then follow the detailed provisioning steps described in Provision API hub in the Cloud console.

  • Use the command line or Terraform.

Attach your API Gateway project to API hub

Attach your API Gateway project to API hub.

Google Cloud console

To attach an API Gateway project to API hub, do the following:

  1. In the Google Cloud console, go to the API hub page.

    Go to API hub

  2. Click Settings from the left navigation menu to open the Settings page.
  3. Go to the Project associations tab.
  4. If your API Gateway project is not in the list of attached runtime projects, do the following:
    1. Click Attach runtime project.
      This displays the Select a resource pane.
    2. Click the Google Cloud project where API Gateway is provisioned.
    3. In the Project association settings pane, select API Gateway and any other API assets you want to automatically import.
    4. Click Save.
  5. If your API Gateway project is already on the list of attached runtime projects, do the following:
    1. Click Edit settings in the row associated with the API Gateway runtime project.
    2. In the Project association settings pane, select API Gateway and any other API assets you want to automatically import.
    3. Click Save.

REST

To attach your API Gateway project to API hub, use the Create runtime project attachments and Create plugin instance APIs.

For example, to create the runtime project attachment:

curl "https://apihub.googleapis.com/v1/projects/HUB_PROJECT_ID/locations/HUB_LOCATION/runtimeProjectAttachments?runtimeProjectAttachmentId=RUNTIME_PROJECT_ID" \
  -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -d '{"runtimeProject":"projects/RUNTIME_PROJECT_ID"}'

Replace the following:

  • HUB_PROJECT_ID: The name of your API hub host project. The host project was selected when API hub was provisioned.
  • HUB_LOCATION: The location of the host project. The location was chosen when API hub was provisioned.
  • RUNTIME_PROJECT_ID: The name of your API Gateway runtime project.

If successful, an RuntimeProjectAttachment JSON object is returned.

Then, to create the API Gateway plugin instance:

curl "https://apihub.googleapis.com/v1/projects/HUB_PROJECT_ID/locations/HUB_LOCATION/plugins/PLUGIN_TYPE/instances" \
  -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "API Gateway Plugin Instance",
    "sourceProjectId": "RUNTIME_PROJECT_ID",
    "actions": [
      {
        "actionId": "sync-metadata"
      }
    ]
  }'

Replace the following:

  • HUB_PROJECT_ID: The name of your API hub host project. The host project was selected when API hub was provisioned.
  • HUB_LOCATION: The location of the host project. The location was chosen when API hub was provisioned.
  • PLUGIN_TYPE: Type of plugin. Set to system-api-gateway.
  • RUNTIME_PROJECT_ID: The name of your API Gateway runtime project.

If successful, an Operation JSON object is returned.