Get started using the Apigee APIs (Alpha)

Get started developing applications with Apigee hybrid using the Apigee APIs, as described in the following sections.

Enable the API

Ensure that you have enabled the Apigee API. The simplest way to enable an API for your project is to use the Google Cloud Platform (GCP) Console. For complete details, see Enable the Apigee API Service.

Obtain an OAuth 2.0 access token

The Apigee APIs support OAuth 2.0 for user authentication. With OAuth 2.0, you exchange your GCP credentials for an access token that you can then use to make secure calls to the Apigee APIs. Once you obtain a token, you do not need to exchange your credentials again until the token expires.

To obtain an OAuth 2.0 access token:

  1. Generate a key for your service account using the GCP console, as described in Creating and managing service account keys.

    A JSON file that contains your service account credentials is downloaded to your computer.

  2. Using your GCP credentials, you can obtain an OAuth 2.0 access token to pass with calls to the Apigee APIs using one of the following methods.

    gcloud

    Use gcloud to obtain an OAuth 2.0 access token, passing the service account credentials JSON file that you downloaded in step 1 using GOOGLE_APPLICATION_CREDENTIALS environment variable. For more information, see gcloud beta auth application-default print-access-token.

    $ export GOOGLE_APPLICATION_CREDENTIALS=~/sa-credentials-file.json
    $ gcloud auth application-default print-access-token

    oauth2l utility

    Use oauth2l to obtain an OAuth 2.0 access token, passing the service account credentials JSON file that you downloaded in step 1.

    oauth2l fetch --json ~/sa-credentials-file.json cloud-platform

    An OAuth2.0 token is returned.

  3. Copy the OAuth 2.0 token returned and store it in a variable, such as TOKEN. For example:
    export TOKEN=ya29....Ts13inj3LrqMJlztwygtM
  4. When you call the Apigee APIs, pass the OAuth 2.0 access token in the Authorization header. For example:
    curl "https://apigee.googleapis.com/v1/organizations/myorg/apis/myApiProxy" \
    -X GET \
    -H "Authorization: Bearer $TOKEN"
    

Use curl

The examples within this section use curl to demonstrate how to develop applications using the Apigee APIs. curl is an open source, command-line tool for transferring data with URL syntax, supporting common protocols such as HTTP and HTTPS.

The following table summarizes the curl command-line options used in the examples.

Option Description
-d '{}'

--data @filename

--data-binary @filename

Defines the request body, which you can pass directly or by specifying a filename.
-F file=@filename

--form file=@filename

Defines form-based data that you can pass by specifying a filename.
-H

--header

Defines a request header.

You must pass the following information in the request header:

  • Authorization header: OAuth 2.0 token for user authentication, as described in Obtain an OAuth 2.0 access token.
  • Content-Type header: Content type of the request body being sent when creating or updating a resource (POST, PATCH, PUT) using the APIs.
-X Specifies the type of request (GET, POST, and so on).

For example:

curl "https://apigee.googleapis.com/v1/organizations/myorg/apis" \
-X GET \
-H "Authorization: Bearer $TOKEN"

Where $TOKEN is set to your OAuth 2.0 access token, as described in Obtain an OAuth 2.0 access token.