Thanks for the question. Here's an end-to-end example for (a) setting up a mediation group using the POST MediationGroup API, (b) creating the ad unit mappings using the POST AdUnitMapping API, and (c) subsequently add mediation lines using the PATCH MediationGroup API.
(a) Create mediation group
Setup oauth
```
oauth2l reset && oauth2l header --json client_secret.json
https://www.googleapis.com/auth/admob.monetization```
Create mediation group using POST MediationGroup API.
A few notes:
* xxxxxxxxxxxxxxxx is your account id (can be fetched from
https://developers.google.com/admob/api/reference/rest/v1beta/accounts/list).
* yyyyyyyyyy is your ad unit id (can be fetched from
https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adUnits/list).
* zzzzzzzzzzzzzzzz is your ad unit mapping id (can be fetched from
https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adUnits.adUnitMappings/list).
* ad_source_id is the id of one of the ad source that AdMob Mediation supports. See
https://developers.google.com/admob/api/v1/ad-sources-reference for the full list. You can also obtain the list programatically using
https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adSources/list.
```
curl --http1.0 -X POST
https://admob.googleapis.com/v1beta/accounts/pub-xxxxxxxxxxxxxxxx/mediationGroups -H "Content-Type: application/json" -H "$(oauth2l header --json client_secret.json
https://www.googleapis.com/auth/admob.monetization)" --data @- << EOF
{
"displayName": "test mediation group",
"targeting": {
"platform": "ANDROID",
"format": "BANNER",
"adUnitIds": [
"ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy",
]
},
"state": "ENABLED",
"mediationGroupLines": {
"-1": {
"displayName": "$0.1 line from ad source <ad_source_id>",
"adSourceId": "<ad_source_id>",
"cpmMode": "MANUAL",
"cpmMicros": "100000",
"state": "ENABLED",
"adUnitMappings": {
"ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy":
"accounts/pub-xxxxxxxxxxxxxxxx/adUnits/yyyyyyyyyy/adUnitMappings/zzzzzzzzzzzzzzzz",
},
},
},
}
EOF
```
(b) Create ad unit mappings
Before creating mediation lines, the new lines need to be linked to the ad source via ad unit mappings.
To create ad unit mappings, the request needs to specify the relevant configurations with a list of key-value pairs. The keys can be found from the Adapters resource (
https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adSources.adapters), programatically using the list adapters API:
https://developers.google.com/admob/api/reference/rest/v1beta/accounts.adSources.adapters/list.
(b.1) List adapters
```
curl --http1.0 -X GET
https://admob.googleapis.com/v1beta/accounts/pub-xxxxxxxxxxxxxxxx/adSources/<ad_source_id>/adapters -H "Content-Type: application/json" -H "$(oauth2l header --json client_secret.json
https://www.googleapis.com/auth/admob.monetization)"
```
Look for the adapter entry that matches the platform and format of your mediation group. An example might look like this:
```
{
"name": "accounts/pub-xxxxxxxxxxxxxxxx/adSources/<ad_source_id>/adapters/<adapter_id>",
"adapterId": "adapter_id",
"title": "some ad source's sdk adapter name",
"platform": "ANDROID",
"formats": [
"BANNER",
"INTERSTITIAL",
"BANNER_AND_INTERSTITIAL"
],
"adapterConfigMetadata": [
{
"adapterConfigMetadataId": "adapter_key_id_1",
"adapterConfigMetadataLabel": "some label name 1",
"isRequired": true
},
{
"adapterConfigMetadataId": "adapter_key_id_2",
"adapterConfigMetadataLabel": "some label name 2",
"isRequired": true
}
]
}
```
(b.2) Create ad unit mappings
Now we have enough information to create ad unit mappings. In this example, we'll create 3 new mediation lines with different manual CPMs. Therefore we'll need 3 new ad unit mappings. Repeat the command below 3 times, each with a different value for `ad_unit_configurations[<adapter_key_id_1>]` and `ad_unit_configurations[<adapter_key_id_2>]` pair.
```
curl --http1.0 -X POST
https://admob.googleapis.com/v1beta/accounts/pub-xxxxxxxxxxxxxxxx/adUnits/yyyyyyyyyy/adUnitMappings -H "Content-Type: application/json" -H "$(oauth2l header --json client_secret.json
https://www.googleapis.com/auth/admob.monetization)" --data @- << EOF
{
"adapter_id": adapter_id,
"state": "ENABLED",
"ad_unit_configurations": {
"adapter_key_id_1": "(placeholder for account id)",
"adapter_key_id_2": "(placeholder for placement id)"
}
}
EOF
```
API should return 3 ad unit mapping IDs. They look something like this: `accounts/pub-xxxxxxxxxxxxxxxx/adUnits/yyyyyyyyyy/adUnitMappings/zzzzzzzzzzzzzzzz`.
(c) Add mediation lines
Now we're ready to insert lines using the PATCH MediationGroup API:
```
curl --http1.0 -X PATCH
https://admob.googleapis.com/v1beta/accounts/pub-xxxxxxxxxxxxxxxx/mediationGroups/<mediation_group_id>?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 ~/admob.labpixies.prod.json
https://www.googleapis.com/auth/admob.monetization)" --data @- << EOF
{
"mediationGroupLines": {
"-1": {
"displayName": "0.15 cpm line",
"adSourceId": "<ad_source_id>",
"cpmMode": "MANUAL",
"cpmMicros": "150000",
"state": "ENABLED",
"adUnitMappings": {
"ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy": "accounts/pub-xxxxxxxxxxxxxxxx/adUnits/yyyyyyyyyy/adUnitMappings/<ad unit mapping id 1 from step b.2>"
}
},
"-2": {
"displayName": "0.12 cpm line",
"adSourceId": "<ad_source_id>",
"cpmMode": "MANUAL",
"cpmMicros": "120000",
"state": "ENABLED",
"adUnitMappings": {
"ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy": "accounts/pub-xxxxxxxxxxxxxxxx/adUnits/yyyyyyyyyy/adUnitMappings/<ad unit mapping id 1 from step b.2>"
}
},
"-3": {
"displayName": "0.13 cpm line",
"adSourceId": "<ad_source_id>",
"cpmMode": "MANUAL",
"cpmMicros": "130000",
"state": "ENABLED",
"adUnitMappings": {
"ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy": "accounts/pub-xxxxxxxxxxxxxxxx/adUnits/yyyyyyyyyy/adUnitMappings/<ad unit mapping id 1 from step b.2>"
}
}
}
}
EOF
```
(d) optionally, we can also verify the committed setup in the AdMob UI:
https://apps.admob.com/v2/mediation/groups/<mediation group id>/edit
As for the validation error mentioned earlier in the original post, the AdMob API backend validation system checks the referential integrities across the entities covered by the mediation group, in order to prevent subsequent ads serving issues. For example, the ad unit mappings referenced by the mediation group are expected to be valid. The error message is possibly due to such validation checks. Hope the above example helps. If you're still hitting HTTP 400 validation errors, please feel free to reach out to your AdMob account manager, and we'd be happy to take a deeper look.