Make direct requests

We encourage you to use the client libraries and samples for your implementation. However, if your integration with the API has special needs, such as using an unsupported language, you can make direct requests as described below.

Calling style

REST is a style of software architecture that provides a convenient and consistent approach to requesting and modifying data.

The term REST is short for "Representational State Transfer." In the context of Google APIs, it refers to using HTTP verbs to retrieve and modify representations of data stored by Google.

In a RESTful system, resources are stored in a data store; a client sends a request that the server perform a particular action (such as creating, retrieving, updating, or deleting a resource), and the server performs the action and sends a response, often in the form of a representation of the specified resource.

In Google's RESTful APIs, the client specifies an action using an HTTP verb such as POST, GET, PUT, or DELETE. It specifies a resource by a globally-unique URI of the following form:

https://www.googleapis.com/apiName/apiVersion/resourcePath?parameters

Because all API resources have unique HTTP-accessible URIs, REST enables data caching and is optimized to work with the web's distributed infrastructure.

You may find the method definitions in the HTTP 1.1 standards documentation useful; they include specifications for GET, POST, PUT, and DELETE.

REST in the AdSense Management API

The supported operations map directly to REST HTTP verbs, as described in AdSense Management API operations.

The specific format for AdSense Management API URIs are:

https://adsense.googleapis.com/v2/resourceID?parameters

where resourceID is the identifier for an ad client, ad unit, url channel, custom channel or the reports collection, and parameters are any parameters to apply to the query.

The format of the resourceID path extensions lets you identify the resource on which you are currently operating, for example:

https://adsense.googleapis.com/v2/accounts/account_id/adclients
https://adsense.googleapis.com/v2/accounts/account_id/adclients/adClientId
https://adsense.googleapis.com/v2/accounts/account_id/adclients/adClientId/adunits
https://adsense.googleapis.com/v2/accounts/account_id/adclients/adClientId/adunits/adUnitId
https://adsense.googleapis.com/v2/accounts/account_id/adclients/adClientId/urlchannels
...

The full set of URIs used for each supported operation in the API is summarized in the AdSense Management API Reference document.

Here are a couple of examples of how this works in the AdSense Management API.

List ad clients:

GET https://adsense.googleapis.com/v2/accounts/account_id/adclients/

List ad units in ad client ca-pub-1234567890123456:

GET https://adsense.googleapis.com/v2/accounts/account_id/adclients/ca-pub-1234567890123456/adunits

Data format

JSON (JavaScript Object Notation) is a common, language-independent data format that provides a simple text representation of arbitrary data structures. For more information, see json.org.

Authorizing requests

Note that AdSense doesn't support Service Accounts, instead you must use the Installed Application flow.

Every request your application sends to the AdSense Management API must include an authorization token. The token also identifies your application to Google.

About authorization protocols

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Sign In With Google, some aspects of authorization are handled for you.

Authorizing requests with OAuth 2.0

All requests to the AdSense Management API must be authorized by an authenticated user.

This process is facilitated with an OAuth client ID.

Get an OAuth client ID

Or create one in the Credentials page.

The details of the authorization process, or "flow," for OAuth 2.0 vary somewhat depending on what kind of application you're writing. The following general process applies to all application types:

  1. When your application needs access to user data, it asks Google for a particular scope of access.
  2. Google displays a consent screen to the user, asking them to authorize your application to request some of their data.
  3. If the user approves, then Google gives your application a short-lived access token.
  4. Your application requests user data, attaching the access token to the request.
  5. If Google determines that your request and the token are valid, it returns the requested data.

Some flows include additional steps, such as using refresh tokens to acquire new access tokens. For detailed information about flows for various types of applications, see Google's OAuth 2.0 documentation.

Here's the OAuth 2.0 scope information for the AdSense Management API:

Scope Meaning
https://www.googleapis.com/auth/adsense Read/write access to AdSense data.
https://www.googleapis.com/auth/adsense.readonly Read-only access to AdSense data.

To request access using OAuth 2.0, your application needs the scope information, as well as information that Google supplies when you register your application (such as the client ID and the client secret).

Tip: The Google APIs client libraries can handle some of the authorization process for you. They are available for a variety of programming languages; check the page with libraries and samples for more details.

Making a request

The final step is making the API request. See the reference documentation for specific information.