Getting Started

Use the Google Ad Manager API (Beta) to read your Ad Manager data and run reports.

To make your first API request, complete the following steps:

Get access to an Ad Manager network

If you don't already have one, sign up for an Ad Manager account.

Enable the Ad Manager API

Enable the Ad Manager API in your Google API Console Project.

Authenticate

All API requests must be authenticated using OAuth2.

The Ad Manager API client libraries read credentials from Application Default Credentials. You can set these using environment variables or gcloud.

Service Account

Linux or macOS

export GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH

Windows

set GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH

User credentials

gcloud auth application-default login --scopes="https://www.googleapis.com/auth/admanager"
# End user credentials must specify the cloud project where the API is enabled.
gcloud auth application-default set-quota-project PROJECT_ID

For more information about choosing credential types and creating credentials, see the authentication guide.

Set up your client library

Java

For Maven:

<!-- pom.xml -->
<dependency>
   <groupId>com.google.api-ads</groupId>
   <artifactId>ad-manager</artifactId>
   <version>0.1.0</version>
</dependency>

For Gradle:

implementation 'com.google.api-ads:ad-manager:0.1.0'

Python

Install the client library from PyPi.

pip install google-ads-admanager

Make your first request

Java

import com.google.ads.admanager.v1.GetNetworkRequest;
import com.google.ads.admanager.v1.Network;
import com.google.ads.admanager.v1.NetworkName;
import com.google.ads.admanager.v1.NetworkServiceClient;

public class SyncGetNetwork {

  public static void main(String[] args) throws Exception {
    syncGetNetwork();
  }

  public static void syncGetNetwork() throws Exception {
    try (NetworkServiceClient networkServiceClient = NetworkServiceClient.create()) {
      GetNetworkRequest request =
          GetNetworkRequest.newBuilder()
              .setName(NetworkName.of("[NETWORK_CODE]").toString())
              .build();
      Network response = networkServiceClient.getNetwork(request);
    }
  }
}

More examples can be found on GitHub. For additional client library information, see the Java guide.

Python

from google.ads import admanager_v1


def sample_get_network():
    # Create a client
    client = admanager_v1.NetworkServiceClient()

    # Initialize request argument(s)
    request = admanager_v1.GetNetworkRequest(
        name="name_value",
    )

    # Make the request
    response = client.get_network(request=request)

    # Handle the response
    print(response)

More examples can be found on GitHub. For additional client library information, see the Python guide.

cURL

curl -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
 https://admanager.googleapis.com/v1/networks/NETWORK_CODE