The Campaign Manager 360 API provides programmatic access to information from your
Campaign Manager 360 account. It's used to manage and create campaigns and reports,
just as you would through the Campaign Manager 360 and Report Builder web services.

This guide describes how to get started with the Campaign Manager 360 API.

## Prerequisites

Before using the Campaign Manager 360 API, there are a few prerequisite steps you'll need to
satisfy:

1. **You must have a Campaign Manager 360 account.** See
   [Advertisers/Agencies](https://www.google.com/doubleclick/advertisers/) for signup information.

2. **Your Campaign Manager 360 account must be enabled for API Access.** Most
   accounts have this enabled by default; if you're not sure, contact your
   account representative or the [Campaign Manager 360 support
   team](mailto:dcm-support@google.com) for assistance.

3. **You must have a user profile with access to this account.** Have your
   Campaign Manager 360 account administrator create a user profile associated with
   this account.

4. **Check user profile permissions in the Campaign Manager 360 UI.** These control
   what the user profile can access from the API. There are no separate API
   permissions.

## Create a project

To get started using the Campaign Manager 360 API, you need to first [create
or select a project in the Google API Console and enable the API](https://console.cloud.google.com/start/api?id=dfareporting&credential=client_key). Using this
link guides you through the process and activates the Campaign Manager 360 API
automatically.
Enabling the API for an existing project...

The following steps apply to users who have an existing project and prefer
to activate the Campaign Manager 360 API for it manually.

To enable an API for your project, do the following:

1. [Open the API Library](https://console.cloud.google.com/apis/library) in the Google API Console. If prompted, select a project or create a new one. The API Library lists all available APIs, grouped by product family and popularity.
2. If the API you want to enable isn't visible in the list, use search to find it.
3. Select the API you want to enable, then click the **Enable** button.
4. If prompted, enable billing.
5. If prompted, accept the API's Terms of Service.

### Generate credentials

All requests you make to the Campaign Manager 360 API must be authorized. For a brief
overview of authorization, read about how to [authorize and identify your
application to Google](https://developers.google.com/doubleclick-advertisers/authorizing).

The following instructions guide you through the process of creating an OAuth
2.0 client ID to use with the [installed application
flow](https://developers.google.com/identity/protocols/OAuth2InstalledApp). For instructions on generating credentials for use
with the service account flow, refer to the [Service Accounts](https://developers.google.com/doubleclick-advertisers/service_accounts)
guide.

1. Follow the steps to [configure a Google API Console project](https://developers.google.com/doubleclick-advertisers/getting_started#create_project).


2. Open the [Credentials page](https://console.cloud.google.com/apis/credentials) in the API Console.
3. Click **CREATE CREDENTIALS \> OAuth client ID**.

   1. If you hadn't configured an OAuth consent screen for this project
      previously, you'll be directed to do so now. Click **CONFIGURE CONSENT
      SCREEN**.

   2. Select the user type and click **CREATE**.

   3. Fill out the initial form. You can edit this later if needed. Click
      **Save** when done.

   4. Navigate back to **Credentials \> CREATE CREDENTIALS \> OAuth client ID** to
      continue.

4. Select **Desktop app** as the application type, give it a name, then click
   **Create**.

When done, you'll be presented with an OAuth 2.0 client ID and client
secret, which you can download in JSON format and save for later use.
Configuring the user consent screen...

When you use OAuth 2.0 for authentication, your users are authenticated
after they agree to terms presented to them on a user consent screen.

To set up your project's consent screen, do the following:

1. Open the [Consent Screen page](https://console.cloud.google.com/apis/credentials/consent) in the Google API Console. If prompted, select a project or create a new one.
2. Fill out the form and click **Save**.

## Install a client library

The Campaign Manager 360 API is built on HTTP and JSON, so any standard HTTP client can send
requests to it and parse the responses.

However, the Google API client libraries provide better language integration,
improved security, and support for making authorized requests. The client
libraries are available in a number of programming languages; by using them you
can avoid the need to manually set up HTTP requests and parse the responses.

To get started, select the programming language that you're using for
development.

### C#

Install the latest [Campaign Manager 360 API client library for .NET](https://www.nuget.org/packages?q=Google.Apis.Dfareporting&prerelease=true&sortOrder=relevance). Using
[NuGet](https://www.nuget.org) to manage your installation is recommended.

Open the NuGet Package Manager Console and run the following command:

```
Install-Package Google.Apis.Dfareporting.v5
```

#### Learn More

- Read the [Google API Client Library for .NET developer's guide](https://developers.google.com/api-client-library/dotnet/get_started).

### Java

Install the latest [Campaign Manager 360 API client library for Java](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.google.apis%22%20AND%20a%3A%22google-api-services-dfareporting%22). Using
[Maven](https://maven.apache.org) to manage your installation is recommended.

Add the following dependency to your `pom.xml` file:

```java
<dependency>
  <groupId>com.google.apis</groupId>
  <artifactId>google-api-services-dfareporting</artifactId>
  <version>v5-rev20260511-2.0.0</version>
  <exclusions>
    <exclusion>
      <groupId>com.google.guava</groupId>
      <artifactId>guava-jdk5</artifactId>
    </exclusion>
  </exclusions>
</dependency>
```

#### Learn More

- Read the [Google API Client Library for Java developer's guide](https://developers.google.com/api-client-library/java/).

### PHP

Install the latest [Campaign Manager 360 API client library for PHP](https://github.com/google/google-api-php-client). Using
[Composer](https://getcomposer.org) to manage your installation is recommended.

Open a terminal and run the following command:

```
composer require google/apiclient
```

If you've already installed the library and just want to update to the
latest version:

```
composer update google/apiclient
```

Depending on your system, you may need to prepend these commands with
`sudo`.

#### Learn More

- Read the [Google API Client Library for PHP developer's guide](https://developers.google.com/api-client-library/php).

### Python

Install the latest [Campaign Manager 360 API client library for Python](https://github.com/google/google-api-python-client). Using
[pip](https://pip.pypa.io) to manage your installation is recommended.

Open a terminal and run the following command:

```
pip install --upgrade google-api-python-client
```

Depending on your system, you may need to prepend these commands with
`sudo`.

#### Learn More

- Browse the [library reference documentation for the Campaign Manager 360 API](https://googleapis.github.io/google-api-python-client/docs/dyn/dfareporting_v5.html).
- Read the [Google API Client Library for Python (v1/v2) developer's guide](https://developers.google.com/api-client-library/python).

### Ruby

Install the latest [Campaign Manager 360 API client library for Ruby](https://github.com/google/google-api-ruby-client). Using
[RubyGems](https://rubygems.org) to manage your installation is recommended.

Open a terminal and run the following command:

```
gem install google-api-client
```

If you've already installed the library and just want to update to the
latest version:

```
gem update -y google-api-client
```

Depending on your system, you may need to prepend these commands with
`sudo`.

#### Learn More

- Read the [Google API Client Library for Ruby developer's guide](https://developers.google.com/api-client-library/ruby/start/get_started).

More supported languages can be found on the [Client
Libraries](https://developers.google.com/doubleclick-advertisers/libraries) page.

## Make a request

With [OAuth 2.0 credentials created](https://developers.google.com/doubleclick-advertisers/getting_started#credentials) and a [client library
installed](https://developers.google.com/doubleclick-advertisers/getting_started#client_lib), you're ready to start using the Campaign Manager 360 API. Learn how
to authorize, configure your client, and make your first request by following
the quickstart below.

### C#

1. **Load the client secrets file and generate authorization credentials.**


   The first time you perform this step you'll be asked to accept an authorization prompt in your browser. Before accepting, make sure you're logged in with a Google Account that has access to Campaign Manager 360. Your application will be authorized to access data on behalf of whichever account is currently logged in.

   ```c#
   // Load client secrets from the specified JSON file.
   GoogleClientSecrets clientSecrets;
   using(Stream json = new FileStream(pathToJsonFile, FileMode.Open, FileAccess.Read)) {
     clientSecrets = GoogleClientSecrets.FromStream(json);
   }

   // Create an asynchronous authorization task.
   //
   // Note: providing a data store allows auth credentials to be cached, so they survive multiple
   // runs of the application. This avoids prompting the user for authorization every time the
   // access token expires, by remembering the refresh token. The "user" value is used to
   // identify a specific set of credentials within the data store. You may provide different
   // values here to persist credentials for multiple users to the same data store.
   Task<UserCredential> authorizationTask = GoogleWebAuthorizationBroker.AuthorizeAsync(
       clientSecrets.Secrets,
       OAuthScopes,
       "user",
       CancellationToken.None,
       dataStore,
       new ManualCodeReceiver());

   // Authorize and persist credentials to the data store.
   UserCredential credential = authorizationTask.Result;
   ```
2. **Create an authorized Dfareporting client.**

   ```c#
   // Create a Dfareporting service object.
   //
   // Note: application name should be replaced with a value that identifies your application.
   service = new DfareportingService(
       new BaseClientService.Initializer {
         HttpClientInitializer = credential,
         ApplicationName = "C# installed app sample"
       }
   );
   ```
3. **Perform an operation.**

   ```c#
   // Retrieve and print all user profiles for the current authorized user.
   UserProfileList profiles = service.UserProfiles.List().Execute();

   foreach (UserProfile profile in profiles.Items) {
     Console.WriteLine("Found user profile with ID {0} and name \"{1}\".",
         profile.ProfileId, profile.UserName);
   }
   ```

### Java

1. **Load the client secrets file and generate authorization credentials.**


   The first time you perform this step you'll be asked to accept an authorization prompt in your browser. Before accepting, make sure you're logged in with a Google Account that has access to Campaign Manager 360. Your application will be authorized to access data on behalf of whichever account is currently logged in.

   ```java
   // Load the client secrets JSON file.
   GoogleClientSecrets clientSecrets =
       GoogleClientSecrets.load(
           jsonFactory, Files.newBufferedReader(Paths.get(pathToClientSecretsFile), UTF_8));

   // Set up the authorization code flow.
   //
   // Note: providing a DataStoreFactory allows auth credentials to be cached, so they survive
   // multiple runs of the program. This avoids prompting the user for authorization every time the
   // access token expires, by remembering the refresh token.
   GoogleAuthorizationCodeFlow flow =
       new GoogleAuthorizationCodeFlow.Builder(
               httpTransport, jsonFactory, clientSecrets, OAUTH_SCOPES)
           .setDataStoreFactory(dataStoreFactory)
           .build();

   // Authorize and persist credentials to the data store.
   //
   // Note: the "user" value below is used to identify a specific set of credentials in the data
   // store. You may provide different values here to persist credentials for multiple users to
   // the same data store.
   Credential credential =
       new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
   ```
2. **Create an authorized Dfareporting client.**

   ```java
   // Create a Dfareporting client instance.
   //
   // Note: application name below should be replaced with a value that identifies your
   // application. Suggested format is "MyCompany-ProductName/Version.MinorVersion".
   Dfareporting reporting =
       new Dfareporting.Builder(credential.getTransport(), credential.getJsonFactory(), credential)
           .setApplicationName("dfareporting-java-installed-app-sample")
           .build();
   ```
3. **Perform an operation.**

   ```java
   // Retrieve and print all user profiles for the current authorized user.
   UserProfileList profiles = reporting.userProfiles().list().execute();
   for (int i = 0; i < profiles.getItems().size(); i++) {
     System.out.printf("%d) %s%n", i + 1, profiles.getItems().get(i).getUserName());
   }
   ```

### PHP

1. **Load the client secrets file and generate authorization credentials.**


   The first time you perform this step you'll be asked to accept an authorization prompt in your browser. Before accepting, make sure you're logged in with a Google Account that has access to Campaign Manager 360. Your application will be authorized to access data on behalf of whichever account is currently logged in.

   ```php
   // Create a Google_Client instance.
   //
   // Note: application name should be replaced with a value that identifies
   // your application. Suggested format is "MyCompany-ProductName".
   $client = new Google_Client();
   $client->setAccessType('offline');
   $client->setApplicationName('PHP installed app sample');
   $client->setRedirectUri(self::OAUTH_REDIRECT_URI);
   $client->setScopes(self::$OAUTH_SCOPES);

   // Load the client secrets file.
   $client->setAuthConfig($pathToJsonFile);

   // Try to load cached credentials from the token store. Using a token store
   // allows auth credentials to be cached, so they survive multiple runs of
   // the application. This avoids prompting the user for authorization every
   // time the access token expires, by remembering the refresh token.
   if (file_exists($tokenStore) && filesize($tokenStore) > 0) {
       $client->setAccessToken(file_get_contents($tokenStore));
   } else {
       // If no cached credentials were found, authorize and persist
       // credentials to the token store.
       print 'Open this URL in your browser and authorize the application.';
       printf("\n\n%s\n\n", $client->createAuthUrl());
       print 'Enter the authorization code: ';
       $code = trim(fgets(STDIN));
       $client->authenticate($code);

       file_put_contents($tokenStore, json_encode($client->getAccessToken()));
   }
   ```
2. **Create an authorized Dfareporting client.**

   ```php
   // Create a Dfareporting service object.
   $service = new Google_Service_Dfareporting($client);
   ```
3. **Perform an operation.**

   ```php
   // Retrieve and print all user profiles for the current authorized user.
   $result = $service->userProfiles->listUserProfiles();
   foreach ($result['items'] as $userProfile) {
       printf(
           "User profile \"%s\" (ID: %d) found for account %d.\n",
           $userProfile->getUserName(),
           $userProfile->getProfileId(),
           $userProfile->getAccountId()
       );
   }
   ```

### Python

1. **Load the client secrets file and generate authorization credentials.**


   The first time you perform this step you'll be asked to accept an authorization prompt in your browser. Before accepting, make sure you're logged in with a Google Account that has access to Campaign Manager 360. Your application will be authorized to access data on behalf of whichever account is currently logged in.

   ```python
   # Set up a Flow object to be used if we need to authenticate.
   flow = client.flow_from_clientsecrets(
       path_to_client_secrets_file, scope=OAUTH_SCOPES)

   # Check whether credentials exist in the credential store. Using a credential
   # store allows auth credentials to be cached, so they survive multiple runs
   # of the application. This avoids prompting the user for authorization every
   # time the access token expires, by remembering the refresh token.
   storage = Storage(CREDENTIAL_STORE_FILE)
   credentials = storage.get()

   # If no credentials were found, go through the authorization process and
   # persist credentials to the credential store.
   if credentials is None or credentials.invalid:
     credentials = tools.run_flow(flow, storage,
                                  tools.argparser.parse_known_args()[0])

   # Use the credentials to authorize an httplib2.Http instance.
   http = credentials.authorize(httplib2.Http())
   ```
2. **Create an authorized Dfareporting client.**

   ```python
   # Construct a service object via the discovery service.
   service = discovery.build('dfareporting', 'v5', http=http)
   ```
3. **Perform an operation.**

   ```python
   # Construct the request.
   request = service.userProfiles().list()

   # Execute request and print response.
   response = request.execute()

   for profile in response['items']:
     print('Found user profile with ID %s and user name "%s".' %
           (profile['profileId'], profile['userName']))
   ```

### Ruby

1. **Load the client secrets file and generate authorization credentials.**


   The first time you perform this step you'll be asked to accept an authorization prompt in your browser. Before accepting, make sure you're logged in with a Google Account that has access to Campaign Manager 360. Your application will be authorized to access data on behalf of whichever account is currently logged in.

   ```ruby
   # Load client ID from the specified file.
   client_id = Google::Auth::ClientId.from_file(path_to_json_file)

   # Set up the user authorizer.
   #
   # Note: providing a token store allows auth credentials to be cached, so they
   # survive multiple runs of the application. This avoids prompting the user for
   # authorization every time the access token expires, by remembering the
   # refresh token.
   authorizer = Google::Auth::UserAuthorizer.new(
     client_id, [API_NAMESPACE::AUTH_DFAREPORTING], token_store
   )

   # Authorize and persist credentials to the data store.
   #
   # Note: the 'user' value below is used to identify a specific set of
   # credentials in the token store. You may provide different values here to
   # persist credentials for multiple users to the same token store.
   authorization = authorizer.get_credentials('user')
   if authorization.nil?
     puts format(
       "Open this URL in your browser and authorize the application.\n\n%s" \
       "\n\nEnter the authorization code:",
       authorizer.get_authorization_url(base_url: OAUTH_REDIRECT_URI)
     )
     code = STDIN.gets.chomp
     authorization = authorizer.get_and_store_credentials_from_code(
       base_url: OAUTH_REDIRECT_URI, code: code, user_id: 'user'
     )
   end
   ```
2. **Create an authorized Dfareporting client.**

   ```ruby
   # Create a Dfareporting service object.
   #
   # Note: application name should be replaced with a value that identifies
   # your application. Suggested format is "MyCompany-ProductName".
   service = API_NAMESPACE::DfareportingService.new
   service.authorization = authorization
   service.client_options.application_name = 'Ruby installed app sample'
   service.client_options.application_version = '1.0.0'
   ```
3. **Perform an operation.**

   ```ruby
   // Retrieve and print all user profiles for the current authorized user.
   UserProfileList profiles = service.UserProfiles.List().Execute();

   foreach (UserProfile profile in profiles.Items) {
     Console.WriteLine("Found user profile with ID {0} and name \"{1}\".",
         profile.ProfileId, profile.UserName);
   }
   ```

## Learn more

Visit the [API Reference](https://developers.google.com/doubleclick-advertisers/current) to learn about all of the services the
API has to offer. Every method detail page has an embedded API
Explorer you can use to make test requests directly from your
browser.

Review our other guides which cover advanced topics and provide end-to-end
examples for common tasks.

When you're ready to start writing code, feel free to explore our extensive
collection of [code samples](https://developers.google.com/doubleclick-advertisers/libraries), which may be modified and
extended to fit your needs.