To discuss and provide feedback on our products, join the official Ad Manager Discord channel in the Google Advertising and Measurement Community server.

Getting Started

  • To use the Google Ad Manager API, you need to get access to an Ad Manager network and enable the Ad Manager API in your Google API Console Project.

  • All API requests must be authenticated using OAuth2, and you can reuse a Service Account if you already have one for the Google Ad Manager SOAP API.

  • The Ad Manager API client libraries read credentials from Application Default Credentials, which can be set using environment variables or gcloud.

  • To make your first API request, you need to set up your client library for your preferred language and then make a request, such as getting network information.

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

exportGOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH

Windows

set GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH

User credentials

gcloudauthapplication-defaultlogin--scopes="https://www.googleapis.com/auth/admanager"
# End user credentials must specify the cloud project where the API is enabled.
gcloudauthapplication-defaultset-quota-projectPROJECT_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.

pipinstallgoogle-ads-admanager

.NET

Install the client library from NuGet.

From the .NET CLI:

dotnetaddpackageGoogle.Ads.AdManager.V1--version1.0.0-beta01

As a package reference:

<PackageReferenceInclude="Google.Ads.AdManager.V1"Version="1.0.0-beta01"/>

PHP

Install the client library from Composer.

composerrequiregoogleads/ad-manager

Ruby

Install the client library from RubyGems.

Gemfile:

gem 'google-ads-ad_manager', '~> 0.2.0'

Install:

geminstallgoogle-ads-ad_manager

Node.js

Install the client library from npm.

From the command line:

npminstall@google-ads/admanager

As a package reference:

// package.json
"dependencies":{
"@google-ads/admanager":"^0.1.0"
}

Make your first request

Java

importcom.google.ads.admanager.v1.GetNetworkRequest;
importcom.google.ads.admanager.v1.Network;
importcom.google.ads.admanager.v1.NetworkName;
importcom.google.ads.admanager.v1.NetworkServiceClient;
publicclass SyncGetNetwork{
publicstaticvoidmain(String[]args)throwsException{
syncGetNetwork();
}
publicstaticvoidsyncGetNetwork()throwsException{
try(NetworkServiceClientnetworkServiceClient=NetworkServiceClient.create()){
GetNetworkRequestrequest=
GetNetworkRequest.newBuilder()
.setName(NetworkName.of("NETWORK_CODE").toString())
.build();
Networkresponse=networkServiceClient.getNetwork(request);
}
}
}

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

Python

fromgoogle.adsimport admanager_v1
defsample_get_network():
 # Create a client
 client = admanager_v1.NetworkServiceClient()
 # Initialize request argument(s)
 request = admanager_v1.GetNetworkRequest(
 name="networks/NETWORK_CODE",
 )
 # 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.

.NET

usingGoogle.Ads.AdManager.V1;
publicsealedpartialclassGeneratedNetworkServiceClientSnippets
{
publicvoidGetNetwork()
{
// Create client
NetworkServiceClientnetworkServiceClient=NetworkServiceClient.Create();
// Initialize request argument(s)
stringname="networks/NETWORK_CODE";
// Make the request
Networkresponse=networkServiceClient.GetNetwork(name);
}
}

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

PHP

<?php

use Google\Ads\AdManager\V1\Client\NetworkServiceClient;
use Google\Ads\AdManager\V1\GetNetworkRequest; use Google\Ads\AdManager\V1\Network; use Google\ApiCore\ApiException; /** * Retrieves a `Network` object. * * @param string $formattedName Resource name of Network. * Format: networks/{network_code} * Please see {@see NetworkServiceClient::networkName()} for help formatting this field. */ function get_network_sample(string $formattedName): void { // Create a client. $networkServiceClient = new NetworkServiceClient(); // Prepare the request message. $request = (new GetNetworkRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var Network $response */ $response = $networkServiceClient->getNetwork($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * */ function callSample(): void { $formattedName = NetworkServiceClient::networkName('NETWORK_CODE'); get_network_sample($formattedName); }

More examples can be found on GitHub.

Ruby

require"google/ads/ad_manager/v1"
defget_network
# Create a client object. The client can be reused for multiple calls.
client=Google::Ads::AdManager::V1::NetworkService::Rest::Client.new
# Create a request. To set request fields, pass in keyword arguments.
request=Google::Ads::AdManager::V1::GetNetworkRequest.new(:name=>'networks/NETWORK_CODE)'
# Call the get_network method.
result=client.get_networkrequest
# The returned object is of type Google::Ads::AdManager::V1::Network.
presult
end

More examples can be found on GitHub.

Node.js

// Resource name of the Network
constname='networks/NETWORK_CODE'
// Imports the Admanager library
const{NetworkServiceClient}=require('@google-ads/admanager').v1;
// Instantiates a client
constadmanagerClient=newNetworkServiceClient();
asyncfunctioncallGetNetwork(){
// Construct request
constrequest={
name,
};
// Run request
constresponse=awaitadmanagerClient.getNetwork(request);
console.log(response);
}
callGetNetwork();

More examples can be found on GitHub.

cURL

curl-H"Authorization: Bearer $(gcloudauthapplication-defaultprint-access-token)"\
https://admanager.googleapis.com/v1/networks/NETWORK_CODE

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026年03月05日 UTC.