Create API supply chain dependencies

This page applies to Apigee and Apigee hybrid.

You can create a dependency between APIs, API versions, and API operations in API hub. The high-level process to create a dependency is as follows:

  1. Find two APIs that may have operations that may be dependent. The operations may be in registered APIs or external APIs.
  2. Determine which API is the supplier and which is the consumer. As discussed previously, the consumer invokes the supplier.
  3. Use the Google Cloud console or the Create dependency API to create the dependency between the supplier and consumer.

Create a dependency

You can create a dependency in the console or with the REST API.

Console

To create a dependency using the Google Cloud console, do the following:

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

    Go to API hub
  2. Click Create dependency and provide the following inputs in the Create a new dependency page.
  3. Under General details, do the following:
    1. Specify unique ID: (Optional) The identifier of the dependency. If not provided, a system-generated ID will be used.
    2. Description: (Optional) A brief description of the dependency.
    3. Click Continue.
  4. Under Select supplier resource, do the following:
    1. Resource type: Select Operation as the supplier resource type.
    2. Supplier API: Select the API that supplies the operation.
    3. Version: Select the API version of the supplier API that provides the operation.
    4. Operation: Select the operation that is supplied to the consumer. For example: GET-/items.
    5. Click Continue.
  5. Under Select consumer resource, do the following:
    1. Resource type: Select Operation as the consumer resource type.
    2. Consumer API: Select the API that consumes the operation.
    3. Version: Select the API version of the consumer API that consumes the operation.
    4. Operation: Select the operation that is consumed by the supplier. For example: GET-/categories.
    5. Click Continue.
  6. Optionally, provide values for any user-defined attributes that were defined in Settings.
  7. Click Create. The new dependency appears in the API supply chain page.

REST API

To create a new dependency using the Create a dependency API, use the following command:

  curl -X POST 'https://apihub.googleapis.com/v1/projects/HUB_PROJECT/locations/HUB_LOCATION/dependencies?dependency_id=DEPENDENCY_ID' \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H 'Content-Type: application/json' \
  --d '{
      "description": "DESCRIPTION",
      "supplier": {
          // Specify one of the following:
          "operation_resource_name": RESOURCE_NAME
          // OR
          "external_api_resource_name: RESOURCE_NAME"
      },
      "consumer": {
        // Specify one of the following:
        "operation_resource_name": RESOURCE_NAME
        // OR
        "external_api_resource_name: RESOURCE_NAME"
      }
  }'

Replace the following:

  • HUB_PROJECT: 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.
  • DEPENDENCY_ID: (Optional) The identifier of the dependency. If not provided, a system-generated ID will be used.
  • DESCRIPTION: (Optional) A brief description of the dependency.
  • RESOURCE_NAME: (Required) Either the resource name of an operation in API hub or an external API, depending on which attribute you specify.

    Operation resource names follow this format: projects/PROJECT/locations/LOCATION/apis/API/versions/VERSION/operations/OPERATION

    Operation resource example: "projects/myproject/locations/us-central1/apis/payments-api/versions/locationv1/operations/getlocation".

    External API resource names follow this format: projects/PROJECT/locations/LOCATION/externalApis/EXTERNAL_API

    External API resource example: "projects/myproject/locations/us-central1/externalApis/petstore".

Example:

  curl -X POST 'https://apihub.googleapis.com/v1/projects/myproject/locations/us-central1/dependencies?dependency_id=user-to-pet' \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H 'Content-Type: application/json' \
  --d '{
      "description": "Dependency from user to pet API",
      "consumer": {
          "operation_resource_name": "projects/myproject/locations/us-central1/apis/payments-api/versions/paymentv1/operations/createuser"
      },
      "supplier": {
          "operation_resource_name": "projects/myproject/locations/us-central1/apis/pet-api/versions/petstorev1/operations/addpet"
      }
  }'

Sample response:

{
  "name": "projects/myproject/locations/us-central1/dependencies/user-to-pet",
  "consumer": {
      "displayName": "POST - /v2/user",
      "operationResourceName": "projects/myproject/locations/us-central1/apis/payments-api/versions/version1/operations/createuser"
  },
  "supplier": {
      "displayName": "POST - /v2/pet",
      "operationResourceName": "projects/myproject/locations/us-central1/apis/payments-api/versions/version1/operations/addpet"
  },
  "state": "VALIDATED",
  "description": "Dependency from user to pet API",
  "discoveryMode": "MANUAL",
  "createTime": "2024-04-17T19:33:31.664226Z",
  "updateTime": "2024-04-17T19:33:31.664226Z"
 }

What's next?