Ad unit mappings are third-party configuration settings that map to an AdMob ad
unit and enable it to make an ad request to a third-party ad network.

When creating a mediation group, ad unit mappings are used as a parameter for
each [mediation group line](https://developers.google.com/admob/api/reference/rest/v1beta/accounts.mediationGroups)
as settings for the specified ad unit to make third-party ad network requests.
Unlike on the AdMob UI, ad unit mappings need to be [created](https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adUnits.adUnitMappings/create)
independently outside of mediation groups and mediation group lines.
After creation, you can [list](https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adUnits.adUnitMappings/list)
all ad unit mappings and use them as a parameter when creating or updating
mediation group lines with new ad unit mappings.

<br />

> [!NOTE]
> **Note:** This feature is in limited access. To get access, contact your account manager.

<br />

## Examples

With [OAuth 2.0 credentials created](https://developers.google.com/admob/api/v1/getting-started#credentials),
you're ready to start using the AdMob API. To request access using OAuth
2.0, your application will also need the scope information.

Here's the OAuth 2.0 scope information:

<br />

| Scope | Meaning |
|---|---|
| `https://www.googleapis.com/auth/admob.monetization` | See, create, and edit your AdMob monetization settings. |
| `https://www.googleapis.com/auth/admob.readonly` | See all AdMob data. This may include account information, inventory and mediation settings, reports, and other data. This doesn't include sensitive data, such as payments or campaign details. |

<br />

Get started on creating your first ad unit mapping:

### curl (command line)

### Requests using curl

1. Load the [client secrets file](https://console.cloud.google.com/apis/credentials) 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
   signed in with a Google Account that has access to the AdMob API. Your
   application will be authorized to access data on behalf of whichever
   account is currently logged in.

   For authentication and authorization, we recommend using
   [oauth2l](https://github.com/google/oauth2l), a simple command-line tool for
   working with Google OAuth 2.0. Install oauth2l and run the
   command below, replacing <var translate="no">path_to_credentials_json</var> with a path
   to a `credentials.json` file that you download when registering your
   cloud application. For the first run, the command walks you through the
   OAuth 2.0 authorization flow. Subsequent runs refresh the token
   automatically.

   ```
   oauth2l header --json path_to_credentials_json --scope admob.readonly,admob.monetization
   ```
2. List ad sources.

   Get AdMob ad source information by replacing <var translate="no">pub-XXXXXXXXXXXXXXXX</var>
   with your publisher ID. See the
   [instructions](https://support.google.com/admob/answer/2784578) on how to find
   your publisher ID.

   ```
   curl --http1.0 -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adSources \
    -H "$(oauth2l header --json path_to_credentials_json --scope admob.readonly)"
   ```

   Sample response:

   ```
   {
    "adSources": [
      {
        "name": "accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855",
        "adSourceId": "5450213213286189855",
        "title": "AdMob Network",
      }
    ]
   }
   ```
3. List the adapters.

   Replace <var translate="no">SSSSSSSSSSSSSSSSSSSS</var> with the ad source ID for the
   adapters of interest.

   Use the following command to get a list of adapters:

   ```
   curl --http1.0 -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adSources/SSSSSSSSSSSSSSSSSSSS/adapters \
    -H "$(oauth2l header --json path_to_credentials_json --scope admob.readonly)"
   ```

   Sample response for the AdMob Network ad source with ID
   `5450213213286189855`:

   ```
   {
    "adapters": [
     {
        "name": "accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855/adapters/1",
        "adapterId": "1",
        "title": "AdMob Network Android SDK",
        "platform": "ANDROID",
        "formats": ["BANNER", "INTERSTITIAL",
          "REWARDED", "NATIVE", "REWARDED_INTERSTITIAL", "APP_OPEN"],
        "adapterConfigMetadata": [{
          "adapterConfigMetadataId": "118",
          "adapterConfigMetadataLabel": "Ad unit ID"
        }]
     },
     {
        "name": "accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855/adapters/2",
        "adapterId": "2",
        "title": "AdMob Network iOS SDK",
        "platform": "ANDROID",
        "formats": ["BANNER", "INTERSTITIAL",
          "REWARDED", "NATIVE", "REWARDED_INTERSTITIAL", "APP_OPEN"],
        "adapterConfigMetadata": [{
          "adapterConfigMetadataId": "119",
          "adapterConfigMetadataLabel": "Ad unit ID"
        }]
     }]
   }
   ```
4. Create an ad unit mapping.

   Replace <var translate="no">YYYYYYYYYY</var> with your ad unit ID fragment. The ad unit
   ID fragment is the last 10 digits of your ad unit ID which follows
   the format "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY". See instructions to
   [find your ad unit ID](https://support.google.com/admob/answer/7356431).

   ```
   curl --http1.0 -X POST \
    https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings \
    -H "$(oauth2l header --json path_to_credentials_json --scope admob.monetization)" \
    -H "Content-Type: application/json" --data @- << EOF
   {
      "name": "InMobi ad unit mapping",
      "adapterId": "8",
      "adUnitConfigurations": {
        "174": "inMobiAccountId",
        "176": "inMobiPlacementId"
      }
   }
   EOF
   ```
5. List all ad unit mappings.

   Replace <var translate="no">YYYYYYYYYY</var> with your ad unit ID fragment. The ad unit
   ID fragment is the last 10 digits of your ad unit ID from
   the format "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY". See instructions to
   [find your ad unit ID](https://support.google.com/admob/answer/7356431).

   ```
    curl --http1.0 -X GET \
    https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings \
    -H "$(oauth2l header --json path_to_credentials_json --scope admob.readonly)"
   ```

   ```
   {
    "adUnitMappingName":
    "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/ZZZZZZZZZZ"
      {
        "adapterId": "1",
        "state": "ENABLED",
        "adUnitConfigurations": {
          "adUnitMappingConfigurationKey": "adUnitId",
          "adUnitMappingConfigurationValue": "118",
        }
      }
   }
   ```