Before you begin
To generate the necessary Google Cloud access token, you need to operate within a Google Cloud project. We recommend that you use the project in which you have enabled Cloud Network Insights.
Required roles
To ensure that the user or service account requesting the token has the necessary permissions to use the AppNeta API, ask your administrator to grant the following IAM roles to the user or service account requesting the token on the project in which Cloud Network Insights is enabled:
-
For read-only access to Cloud Network Insights resources:
Cloud Network Insights Viewer (
roles/networkmanagement.CloudNetworkInsightsViewer) -
For edit access to Cloud Network Insights resources:
Cloud Network Insights Editor (
roles/networkmanagement.CloudNetworkInsightsEditor) -
For full access to Cloud Network Insights resources:
Cloud Network Insights Admin (
roles/networkmanagement.CloudNetworkInsightsAdmin)
For more information about granting roles, see Manage access to projects, folders, and organizations.
Your administrator might also be able to give the user or service account requesting the token the required permissions through custom roles or other predefined roles.
Create an AppNeta API token
You can create an AppNeta API token by generating a Google Cloud access token to exchange for a provider-specific token that is used with the AppNeta API.
Generate a Google Cloud access token
Generate a Google Cloud access token for the user or service account that makes the API calls. There are several ways to obtain a Google Cloud access token, depending on your environment and how you're authenticated to Google Cloud:
- Service accounts: if you're running applications on Google Cloud infrastructure (for example, Compute Engine, Google Kubernetes Engine) or using service account keys, you can use the Cloud Client Libraries or the metadata server to fetch tokens.
- Other environments: Google Cloud provides various authentication mechanisms.
See Authentication token types for a comprehensive guide on choosing the best method for your situation.
If you have the Google Cloud CLI installed and configured, you can generate a token to copy using gcloud CLI commands:
gcloud auth print-access-token
If you want application default credentials, use the following gcloud CLI command:
gcloud auth application-default print-access-token
Exchange tokens
Use the copied Google Cloud access token to call the Network Management API to generate a provider-specific access token for AppNeta.
The AppNeta token expires when the
Google Cloud token used to generate it expires. Google Cloud access
tokens are typically valid for one hour. We recommend using a fresh
Google Cloud access token each time you perform the
generateProviderAccessToken call to help maximize the AppNeta
token's lifespan.
gcloud
gcloud network-management network-monitoring-providers generate-provider-access-token NETWORK_MONITORING_PROVIDER --location=global --gcp-access-token=GCP_ACCESS_TOKEN
Replace the following:
NETWORK_MONITORING_PROVIDER: the provider name. Useexternalunless you have actively set a different name.GCP_ACCESS_TOKEN: the token you generated in Google Cloud.
curl
curl -H "Authorization: Bearer GCP_ACCESS_TOKEN"
"https://networkmanagement.googleapis.com/v1/projects/PROJECT_ID/locations/global/networkMonitoringProviders/external:generateProviderAccessToken?gcp_access_token=GCP_ACCESS_TOKEN"
Replace the following:
GCP_ACCESS_TOKEN: the token you generated in Google Cloud.PROJECT_ID: the project where Cloud Network Insights is enabled.
The response from this call contains the providerAccessToken, which you
use to authenticate requests directly against the AppNeta API endpoints.
Use the AppNeta token
Use the providerAccessToken as a bearer token in the authorization header
when making calls to the AppNeta API. For the available endpoints,
parameters, and request and response schemas, see
AppNeta API v4 endpoints and schemas
in the AppNeta documentation.
If you receive a 401 error, generate a new
Google Cloud access token or application default credentials token,
and then exchange tokens again.