[Video](https://www.youtube.com/watch?v=NLHXwQNADY8)

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](https://developers.google.com/ad-manager/api/clients) 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](https://support.google.com/admanager/answer/7084151). You can also create a
[test network](https://developers.google.com/ad-manager/api/environments) 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.

> [!NOTE]
> **Note:** By accessing or using the Ad Manager API you agree to the [Terms of
> Service](https://www.google.com/intl/en_ALL/doubleclick/tos/dfp-api-terms.html).

## 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](https://developers.google.com/ad-manager/api/authentication).

1. Open the [Google API Console
   Credentials page](https://console.cloud.google.com/apis/credentials)

2. From the project menu, choose **Create project** , enter a name for the
   project, and optionally, edit the provided Project ID. Click **Create**.

3. On the Credentials page, select **Create credentials** , then select
   **Service account key**.

4. Select [New service
   account](https://console.developers.google.com/apis/credentials/serviceaccountkey)
   and select `JSON` as the key type.

5. Click **Create** to download a file containing a private key.

## Configure your Ad Manager network

1. [Sign in](https://admanager.google.com/) to Google Ad
   Manager.

2. In the sidebar, click **Admin \> Global settings**.

3. Under **General settings \> Api access** click the slider to **Enabled**.

4. Click the **Save** button at the bottom of the page.

## Set up your client

Download one of the [Ad Manager client libraries](https://developers.google.com/ad-manager/api/clients). 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

[Video](https://www.youtube.com/watch?v=RaNqYIi8cPo)

Here is a basic example that shows how to use the [Java client
library](https://github.com/googleads/googleads-java-lib). For more detailed usage information, refer to
the [README](https://github.com/googleads/googleads-java-lib/blob/main/README.md)
file in the client library distribution.

1. **Setup your credentials**

   Run the following command in a shell:

   ```console
   curl https://raw.githubusercontent.com/googleads/googleads-java-lib/main/examples/admanager_axis/src/main/resources/ads.properties -o ~/ads.properties
   ```
   Open the `~/ads.properties` file 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
   [...]
   ```
2. **Specify dependencies**

   Edit your `pom.xml` file and add the following to the
   `dependencies` tag. You can find the latest version number on [Github](https://github.com/googleads/googleads-java-lib/releases).

   ```xml
   <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>
   ```
3. **Write some code and make a request!**

   ```java
   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);

       // Make a request
       Network network = networkService.getCurrentNetwork();

       System.out.printf("Current network has network code '%s' and display" +
           " name '%s'.%n", network.getNetworkCode(), network.getDisplayName());
     }
   }
   ```
   [View on GitHub](https://github.com/googleads/googleads-java-lib/blob/main/examples/admanager_axis/src/main/java/admanager/axis/v202608/networkservice/GetCurrentNetwork.java)

### Python

[Video](https://www.youtube.com/watch?v=HrBS8fqD7-g)

Here is a basic example that shows how to use the [Python client library](https://github.com/googleads/googleads-python-lib).
The Python Client Library supports Python v3.6+. For more detailed usage
information, refer to the [README](https://github.com/googleads/googleads-python-lib/blob/main/README.md)
file in the client library distribution.

1. **Install the library and set up your credentials.**

   Run the following commands in a shell:

       python3 -m pip install googleads
       curl https://raw.githubusercontent.com/googleads/googleads-python-lib/main/googleads.yaml \
            -o ~/googleads.yaml

2. **Set up your `~/googleads.yaml` file.**

   Fill in the following fields:

   ```yaml
   ad_manager:
     application_name: INSERT_APPLICATION_NAME_HERE
     network_code: INSERT_NETWORK_CODE_HERE
     path_to_private_key_file: INSERT_PATH_TO_FILE_HERE
   ```
3. **Run some code and make a request.**

   ```python
   # Import the library.
   from googleads import ad_manager

   # Initialize a client object, by default uses the credentials in ~/googleads.yaml.
   client = ad_manager.AdManagerClient.LoadFromStorage()

   # Initialize a service.
   network_service = client.GetService('NetworkService', version='v202608')

   # Make a request.
   current_network = network_service.getCurrentNetwork()

   print("Current network has network code '%s' and display name '%s'." %
           (current_network['networkCode'], current_network['displayName']))
   ```
   [View on GitHub](https://github.com/googleads/googleads-python-lib/blob/main/examples/ad_manager/v202608/network_service/get_current_network.py)

### PHP

[Video](https://www.youtube.com/watch?v=VDgSYNQhaRk)

Here is a basic example that shows how to use the
[PHP client library](https://github.com/googleads/googleads-php-lib).

1. **Install the library and setup your credentials.**

   Run the following commands in a shell to install the client library and download the
   [adsapi_php.ini](https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdManager/adsapi_php.ini)
   file to your home directory:

       composer require googleads/googleads-php-lib
       curl https://raw.githubusercontent.com/googleads/googleads-php-lib/main/examples/AdManager/adsapi_php.ini -o ~/adsapi_php.ini

2. **Setup your `~/adsapi_php.ini` file.**

   Fill in the following fields:

   ```ini
   [AD_MANAGER]
   networkCode = "INSERT_NETWORK_CODE_HERE"
   applicationName = "INSERT_APPLICATION_NAME_HERE"

   [OAUTH2]
   jsonKeyFilePath = "INSERT_ABSOLUTE_PATH_TO_OAUTH2_JSON_KEY_FILE_HERE"
   scopes = "https://www.googleapis.com/auth/dfp"
   ```
3. **Run some code and make a request!** This example code must be run from the command line, not a browser. The file containing this code must reside in the root of the project directory, where `composer require` was run.

   ```php
   <?php
   require 'vendor/autoload.php';
   use Google\AdsApi\AdManager\AdManagerSession;
   use Google\AdsApi\AdManager\AdManagerSessionBuilder;
   use Google\AdsApi\AdManager\v202608\ApiException;
   use Google\AdsApi\AdManager\v202608\ServiceFactory;
   use Google\AdsApi\Common\OAuth2TokenBuilder;

   // Generate a refreshable OAuth2 credential for authentication.
   $oAuth2Credential = (new OAuth2TokenBuilder())
       ->fromFile()
       ->build();
   // Construct an API session configured from a properties file and the OAuth2
   // credentials above.
   $session = (new AdManagerSessionBuilder())
       ->fromFile()
       ->withOAuth2Credential($oAuth2Credential)
       ->build();

   // Get a service.
   $serviceFactory = new ServiceFactory();
   $networkService = $serviceFactory->createNetworkService($session);

   // Make a request
   $network = $networkService->getCurrentNetwork();
   printf(
       "Network with code %d and display name '%s' was found.\n",
       $network->getNetworkCode(),
       $network->getDisplayName()
   );
   ```
   [View on GitHub](https://github.com/googleads/googleads-php-lib/blob/main/examples/AdManager/v202608/NetworkService/GetCurrentNetwork.php)

### .NET

[Video](https://www.youtube.com/watch?v=P9cC2Q_tMqY)

Here is a basic example that shows how to use the [.NET client
library](https://github.com/googleads/googleads-dotnet-lib)

1. **Create a new project**

   Open Visual Studio and create a new project (Console Application).
2. **Add required library references to your project**

   Add a nuget dependency for [Google.Dfp](https://www.nuget.org/packages/Google.Dfp/).
3. **Setup your App.config**

   Copy src\\App.config to your project directory and add it to your project. If your application has its own App.config, then you can copy the following nodes into your App.config:
   - configuration/AdManagerApi
   - configuration/configSections/section\[name="AdManagerApi"\]
   - configuration/system.net
4. **Setup credentials**

   Open App.config and edit the following keys:

   ```
   <add key="ApplicationName" value="INSERT_YOUR_APPLICATION_NAME_HERE" />
   <add key="NetworkCode" value="INSERT_YOUR_NETWORK_CODE_HERE" />
   <add key="OAuth2Mode" value="SERVICE_ACCOUNT" />
   <add key="OAuth2SecretsJsonPath" value="INSERT_OAUTH2_SECRETS_JSON_FILE_PATH_HERE" />
   ```
5. **Make a call to the library**

   You can call the library as shown in the following C# code snippet
   [View on GitHub](https://github.com/googleads/googleads-dotnet-lib/blob/main/examples/AdManager/CSharp/v202608/InventoryService/GetAllAdUnits.cs)

   ```
   AdManagerUser user = new AdManagerUser();
         using (InventoryService inventoryService = user.GetService<InventoryService>())
               {
                   // Create a statement to select ad units.
                   int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
                   StatementBuilder statementBuilder =
                       new StatementBuilder().OrderBy("id ASC").Limit(pageSize);

                   // Retrieve a small amount of ad units at a time, paging through until all
                   // ad units have been retrieved.
                   int totalResultSetSize = 0;
                   do
                   {
                       AdUnitPage page =
                           inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

                       // Print out some information for each ad unit.
                       if (page.results != null)
                       {
                           totalResultSetSize = page.totalResultSetSize;
                           int i = page.startIndex;
                           foreach (AdUnit adUnit in page.results)
                           {
                               Console.WriteLine(
                                   "{0}) Ad unit with ID \"{1}\" and name \"{2}\" was found.", i++,
                                   adUnit.id, adUnit.name);
                           }
                       }

                       statementBuilder.IncreaseOffsetBy(pageSize);
                   } while (statementBuilder.GetOffset() < totalResultSetSize);

                   Console.WriteLine("Number of results found: {0}", totalResultSetSize);
               }
           
   ```

If you don't want to set your credentials in your App.config, then refer
to [this wiki article](https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started)
for alternate ways of using the AdManagerUser class. For more detailed information about using the .NET Client Library, refer
to the [README](https://github.com/googleads/googleads-dotnet-lib/blob/main/README.md). If you want to develop in .NET without the client library, please refer to the
[NoClientLibrary
wiki article](https://github.com/googleads/googleads-dotnet-lib/wiki/NoClientLibrary).

### Ruby

[Video](https://www.youtube.com/watch?v=_b3Bg5Bvpp8)

Here is a basic example that shows how to use the [Ruby
client library](https://github.com/googleads/google-api-ads-ruby/tree/HEAD/ad_manager_api). The Ruby client library requires Ruby 2.1 or later.

1. **Install the Ruby gem and get the configuration file.**

   Run the following commands in a shell:

       gem install google-dfp-api
       curl https://raw.githubusercontent.com/googleads/google-api-ads-ruby/main/ad_manager_api/ad_manager_api.yml -o ~/ad_manager_api.yml

   > [!NOTE]
   > If you encounter an error such as "`cannot load such
   > file -- mkmf (LoadError)`" at any point while installing your gems, you may need to install additional Ruby development libraries such as ruby-dev, ruby-devel, xcode-select etc. for your particular environment.

2. **Setup your credentials**

   Populate the required fields in the `~/ad_manager_api.yml`
   file. If you don't already have an OAuth2 keyfile, you'll need to follow the
   steps to [create your OAuth2
   credentials](https://developers.google.com/ad-manager/api/authentication#service).

   ```ruby
   :authentication:
     :oauth2_keyfile: INSERT_PATH_TO_JSON_KEY_FILE_HERE
     :application_name: INSERT_APPLICATION_NAME_HERE
     :network_code: INSERT_NETWORK_CODE_HERE
   ```
3. **Write some code and make a request!**

   ```ruby
   # Import the library.
   require 'ad_manager_api'

   # Initialize an Ad Manager client instance (uses credentials in ~/ad_manager_api.yml by default).
   ad_manager = AdManagerApi::Api.new

   # Get a service instance.
   network_service = ad_manager.service(:NetworkService, :v202608)

   # Make a request.
   network = network_service.get_current_network()

   puts "The current network is %s (%d)." %
           [network[:display_name], network[:network_code]]
   ```
   [View on GitHub](https://github.com/googleads/google-api-ads-ruby/blob/main/ad_manager_api/examples/v202608/network_service/get_current_network.rb)

More detailed steps for getting started can be found in the [README](https://github.com/googleads/google-api-ads-ruby/wiki/DFP-Readme)
file that is distributed with the Ruby client library. Also, check out our [full
example library](https://github.com/googleads/google-api-ads-ruby/tree/HEAD/ad_manager_api/examples) for Ruby.

## Next steps

When you have a client library up and running, modify the examples provided to
extend them for your needs.

Browse the [reference documentation](https://developers.google.com/ad-manager/api/rel_notes) to learn more
about the API.

If you need help, visit our [Support page](https://developers.google.com/ad-manager/api/community).