Page Summary
-
The Google Ad Manager SOAP API allows building applications to manage inventory, create orders, and pull reports.
-
Client libraries are available for Java, .NET, Python, PHP, and Ruby to help get started with the API.
-
To make your first API request, you need to get access to an Ad Manager network, create authentication credentials using OAuth 2.0, and configure API access in your network settings.
-
After setting up your Ad Manager network and authentication, download and configure one of the provided client libraries to write code and make requests to the API.
You can use the Google Ad Manager SOAP API to build apps that manage inventory, create orders, pull reports, and more.
To help you get started, we offer client libraries for Java, .NET, Python, PHP, and Ruby.
To make your first API request, follow these steps:
Get access to an Ad Manager network
If you don't already have one, sign up for an Ad Manager account. You can also create a test network if you want to test the API in a separate environment. Note that you don't need an AdSense account for test purposes.
Make a note of your network code. You can find this in the URL when you sign in
to your network. For example, in the URL
https://admanager.google.com/1234#home, 1234 is your network code.
Create authentication credentials
You must authenticate all Ad Manager SOAP API requests using OAuth 2.0. The following steps cover the use case of accessing your own Ad Manager data. For more details and other options, see Authentication.
Open the Google API Console Credentials page
From the project menu, choose Create project, enter a name for the project, and optionally, edit the provided Project ID. Click Create.
On the Credentials page, select Create credentials, then select Service account key.
Select New service account and select
JSONas the key type.Click Create to download a file containing a private key.
Configure your Ad Manager network
Sign in to Google Ad Manager.
In the sidebar, click Admin > Global settings.
Under General settings > Api access click the slider to Enabled.
Click the Save button at the bottom of the page.
Set up your client
Download one of the Ad Manager client libraries. The libraries offer wrapper functions and features that make it easier and faster to develop apps.
The following tabs provide quickstarts for coding in each of the languages for which there is a client library.
Java
Here is a basic example that shows how to use the Java client library. For more detailed usage information, refer to the README file in the client library distribution.
- Setup your credentials
Run the following command in a shell:
Open thecurl https://raw.githubusercontent.com/googleads/googleads-java-lib/main/examples/admanager_axis/src/main/resources/ads.properties -o ~/ads.properties~/ads.propertiesfile and populate the following fields:[...] api.admanager.applicationName=INSERT_APPLICATION_NAME_HERE api.admanager.jsonKeyFilePath=INSERT_PATH_TO_JSON_KEY_FILE_HERE api.admanager.networkCode=INSERT_NETWORK_CODE_HERE [...]
-
Specify dependencies
Edit your
pom.xmlfile and add the following to thedependenciestag. You can find the latest version number on Github.<dependency> <groupId>com.google.api-ads</groupId> <artifactId>ads-lib</artifactId> <version>RELEASE</version> </dependency> <dependency> <groupId>com.google.api-ads</groupId> <artifactId>dfp-axis</artifactId> <version>RELEASE</version> </dependency>
-
Write some code and make a request!
import com.google.api.ads.common.lib.auth.OfflineCredentials; import com.google.api.ads.common.lib.auth.OfflineCredentials.Api; import com.google.api.ads.admanager.axis.factory.AdManagerServices; import com.google.api.ads.admanager.axis.v202608.Network; import com.google.api.ads.admanager.axis.v202608.NetworkServiceInterface; import com.google.api.ads.admanager.lib.client.AdManagerSession; import com.google.api.client.auth.oauth2.Credential; public class App { public static void main(String[] args) throws Exception { Credential oAuth2Credential = new OfflineCredentials.Builder() .forApi(Api.AD_MANAGER) .fromFile() .build() .generateCredential(); // Construct an AdManagerSession. AdManagerSession session = new AdManagerSession.Builder() .fromFile() .withOAuth2Credential(oAuth2Credential) .build(); // Construct a Google Ad Manager service factory, which can only be used once per // thread, but should be reused as much as possible. AdManagerServices adManagerServices = new AdManagerServices(); // Retrieve the appropriate service NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);