The AdMob API lets you create, list, and update mediation groups, including:

- Specifying [mediation group targeting](https://developers.google.com/admob/api/reference/rest/v1beta/accounts.mediationGroups#MediationGroupTargeting) including regions, format, platform, and IDFA targeting
- Adding new [mediation group lines](https://developers.google.com/admob/api/reference/rest/v1beta/MediationGroupLine) to an existing mediation group
- Viewing which mediation groups are part of a mediation A/B experiment and what mediation group lines belong to each variant: A or B

<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 />

### Create

To create a mediation group, you must specify the [mediation group targeting](https://developers.google.com/admob/api/reference/rest/v1beta/accounts.mediationGroups#MediationGroupTargeting)
information, including the relevant ad units. The following example creates a new
mediation group for Android interstitial ads for 2 ad units. One mediation group
line is added at creation for the InMobi ad source. You don't need to include
the AdMob network as it will be added at creation time by default.

In the code snippet below, replace `pub-XXXXXXXXXXXXXXXX` with your [publisher
ID](https://support.google.com/admob/answer/2784578).

Then, replace `YYYYYYYYYY` with the last 10 digits of your [ad unit
ID](https://support.google.com/admob/answer/7356431), complying
to the format:

    ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY

As there are two ad units in this example, `YYYYY11111` refers to the first ad
unit and `WWWWW11111` to the first ad unit's mapping. `YYYYY22222` and
`WWWWW22222` refer to the second ad unit and ad unit mapping.

### curl (command line)

Replace `WWWWWWWWWW` with your ad unit mapping ID. The ad unit mapping ID
can be found using the
[`accounts.adUnits.adUnitMappings.list`](https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adUnits.adUnitMappings/list)
method.

```
 curl --http1.0 -X POST https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/mediationGroups
-H "Content-Type:application/json"
-H "$(oauth2l header --json path_to_credentials_json --scope admob.monetization)"
--data @- << EOF
{
  "displayName": "Test Mediation Group"
  "targeting": {
    "platform": "ANDROID",
    "format": "INTERSTITIAL"
    "adUnitIds":["ca-app-pub-XXXXXXXXXXXXXXXX/YYYYY11111", "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYY22222"}
  }
  "mediationGroupLines": {
    "-1": {
      "displayName": "test line",
      "adSourceId": "7681903010231960328",
      "cpmMode": "MANUAL",
      "cpmMicros": "150000",
      "state": "ENABLED",
      "adUnitMappings": {
        "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYY11111": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYY11111/adUnitMappings/WWWWW11111",
        "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYY22222": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYY22222/adUnitMappings/WWWWW22222"
      }
  }
}
```

### List

Replace `pub-XXXXXXXXXXXXXXXX` with your [publisher
ID](https://support.google.com/admob/answer/2784578) to view your mediation groups.

### curl (command line)

Sample request:

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

Sample response:

```
{
"https://developers.google.com/admob/api/reference/rest/v1beta/accounts.mediationGroups": [
  {
    "name": "accounts/pub-XXXXXXXXXXXXXXXX/mediationGroups/ZZZZZZZZZZ",
    "mediationGroupId": "ZZZZZZZZZZ",
    "displayName": "Test Mediation Group",
    "state": "ENABLED",
    "state": "NOT_RUNNING",
    "targeting": {
      "platform": "iOS",
      "format": "BANNER",
      "targetedRegionCodes": "[CA]",
      "adUnits": ["YYYYY11111", "YYYYY22222"]
    },
    "mediationGroupLines": {
      "11111111111111111": {
        "id": "11111111111111111",
        "displayName": "AdMob Network",
        "adSourceId": "5450213213286189855",
        "cpmMode": "LIVE",
        "state": "ENABLED",
        "experimentVariant": "ORIGINAL"
      },
      "22222222222222222": {
        "id": "22222222222222222",
        "displayName": "test line",
        "adSourceId": "7681903010231960328",
        "cpmMode": "MANUAL",
        "cpmMicros": "150000",
        "adUnitMappings": {
          "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYY11111": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYY11111/adUnitMappings/WWWWW11111",
          "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYY22222": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYY22222/adUnitMappings/WWWWW22222"
        },
        "state": "ENABLED",
        "experimentVariant": "ORIGINAL"
      }
    },
  }]
}
```

### Patch

Here is the list of [field
masks](https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/FieldMask)
to update a mediation group. Updates to repeated fields, such as items in a
list, fully replace existing values with new values. Updates to individual
values in a map can be done through indexing by the key.

The following field masks are supported for mediation group updates:

- `targeting.adUnitIds`
- `mediationGroupLines[mediationGroupLineId]`
- `mediationGroupLines[mediationGroupLineId].state`
- `mediationGroupLines[mediationGroupLineId].adUnitMappings[adUnitId]`

To update a mediation group with a new mediation group line, use a distinct
negative number for the `mediationGroupLineId`. To update existing mediation
group lines, reference the mediation group line ID in both the `update_mask` and
the payload as seen below.

    "updateMask" {
        paths: "mediation_group_lines["123"].ad_unit_mappings["456"]"
    }

    "mediationGroup" {
      "mediationGroupLines": {
       "123": {
         "id": "123"
         "adUnitMappings": {
          "456": "newAdUnitMappingId"
         }
        }
      }
    }

### curl (command line)

The example below adds 3 new mediation lines to an existing mediation group.
The `updateMask` includes the 3 mediation group lines with distinct negative
values as the placeholder:

`updateMask=mediationGroupLines["-1"],mediationGroupLines["-2"],mediationGroupLines["-3"]`

You need to translate special characters because all URLs need to conform to
the syntax specified by the Uniform Resource Identifier (URI) specification,
so the `updateMask` becomes:

`updateMask=mediationGroupLines%5B%22-1%22%5D,mediationGroupLines%5B%22-2%22%5D,mediationGroupLines%5B%22-3%22%5D`

To run the following example, replace `pub-XXXXXXXXXXXXXXXX` with your
publisher ID and `ZZZZZZZZZZ` with your mediation group ID. The mediation
group ID can be found in the AdMob UI or by using the [`accounts.mediationGroups:list`](https://developers.google.com/admob/api/reference/rest/v1beta/accounts.mediationGroups/list)
method.

Replace `YYYYYYYYYY` with the last 10 digits of your [ad unit
ID](https://support.google.com/admob/answer/7356431), following the format:

    ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY`

Replace `WWWWWWWWWW` with your ad unit mapping ID. The ad unit mapping ID
can be found using the
[`accounts.adUnits.adUnitMappings.list`](https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adUnits.adUnitMappings/list)
method.

```
curl --http1.0 -X PATCH https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/mediationGroups/ZZZZZZZZZZ?
updateMask=mediationGroupLines%5B%22-1%22%5D,mediationGroupLines%5B%22-2%22%5D,mediationGroupLines%5B%22-3%22%5D
-H "Content-Type:application/json"
-H "$(oauth2l header --json path_to_credentials_json --scope admob.monetization)"
--data @- << EOF
{
"mediationGroupLines": {
  "-1": {
    "displayName": "test line 2",
    "adSourceId": "7681903010231960458",
    "cpmMode": "MANUAL",
    "cpmMicros": "150000",
    "state": "ENABLED",
    "adUnitMappings": {
      "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/WWWWWWWWWW"
    }
},
"-2": {
    "displayName": "test line 3",
    "adSourceId": "7681903010231960328",
    "cpmMode": "MANUAL",
    "cpmMicros": "120000",
    "state": "ENABLED",
    "adUnitMappings": {
      "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/WWWWWWWWWW"
    }
},
"-3": {
    "displayName": "test line 4",
    "adSourceId": "7681903010231960328",
    "cpmMode": "MANUAL",
    "cpmMicros": "130000",
    "state": "ENABLED",
    "adUnitMappings": {
     "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/WWWWWWWWWW"
    }
  }
}
}
EOF
```