I have a verified partner channel on YouTube, and I\'m trying to enable monetization for videos uploaded via the YouTube Data API (v3).
The channel is already enable
The link that Tareq supplied is correct, but unfortunately it only shows some python code instead of what is going on using HTTP. Since I wanted to do the same, here is what I have figured out and what works for me. Note again that you need access to the ContentID API (vote for this ticket to get this fixed) which means you need to have access to a owners of an CMS Account. Confusingly there exists a YouTube Partner Program which has nothing to do with being a "YouTube Partner". You need access to a CMS account which is e.g. the case if you are running an multi channel network (MCN). Additionally I get the impression that the documentation is actually quite well hidden because even if I know exactly what I am looking for I always have a hard time to find the documentation pages again.
Anyway: Here is the stuff:
First you need to create an asset (docs):
POST https://www.googleapis.com/youtube/partner/v1/assets?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...
{
"type": "web",
"metadata": {
"title": "some title, typically the same as the video title",
"customId": "optional, but typically the same as the videoId"
}
}
In the response body you'll find:
{
...
"id": "ASSET_ID"
...
}
Save the ASSET_ID for later.
Now we tell YouTube that we exclusively own everything connected with the asset to 100% exclusively and worldwide (docs):
PUT https://www.googleapis.com/youtube/partner/v1/assets/ASSET_ID/ownership?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...
{
"general": {
"owner": "CONTENT_OWNER_ID",
"ratio": 100,
"type": "exclude"
}
}
Note that this is a PUT request and not a POST!
Now we connect the video, the asset and a policy whith each other (docs)
POST https://www.googleapis.com/youtube/partner/v1/claims?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...
{
"assetId": "ASSET_ID",
"videoId": "VIDEO_ID",
"policy": {
"id": "POLICY_ID"
},
"contentType": "audiovisual"
}
Now your video should will be monetized according to some policy.
In my examples you will of course need to replace the variables I left in there in capital letters:
GET https://www.googleapis.com/youtube/partner/v1/contentOwners?fetchMine=true
(docs)GET https://www.googleapis.com/youtube/partner/v1/policies?onBehalfOfContentOwner=CONTENT_OWNER_ID
(docs)For all the request you need to be authenticated with the scope https://www.googleapis.com/auth/youtubepartner
This is just one way and option set of applying monetizations. The API endpoints that I showed have more and different options. Refer to the docs.
Seems like currently the Data API doesn't respect channel default settings when uploading new videos, nevertheless you can enable monetization (claim ownership) using the Content ID API. See this example
https://developers.google.com/youtube/partner/upload_claim_sample