You can create and update resources, including YouTube resources, programmatically and in bulk by uploading Structured Data Files using the Display & Video 360 API. This page discusses how to prepare and upload a Structured Data File using the API.
Only five Structured Data Files per advertiser ID can be uploaded by a Google Cloud project in a day.
Prepare a Structured Data File for upload
Uploaded Structured Data Files should be modified versions of recently downloaded Structured Data Files of the same file type and from the same advertiser. Prepare the downloaded Structured Data File for upload by making the following updates:
- Add entries for any new resources you want to create.
- Update any existing entries for resources you want to update.
- Remove any entries that are not new or updated in order to reduce file size, speed up processing time, and remove the likelihood for any unintentional updates.
Verify the following before uploading the file:
- The file is a
CSV
file. - All entries in the file are for resources under the same parent advertiser.
Upload a file
Upload a Structured Data File using the
advertisers.sdfuploadtasks.upload
method. This request
creates an SDF upload task Operation
. This long-running
operation processes the uploaded file, creates and updates resources based on
the file contents, and generates result files that list successful and failed
updates.
Here's how to upload a Structured Data File and retrieve the resulting
Operation
:
# Import the object used as the media body for the upload request. from apiclient.http import MediaFileUpload # Provide the parent advertiser ID for the resources in the SDF. # The ID value must be a str and not an int. advertiser_id = advertiser-id # Provide the filename and local path to the media file. sdf_filename = sdf-filename sdf_path = sdf-path # Create the request body. body = { 'filename': sdf_filename, 'advertiserId': advertiser_id } # Create the upload object and use a default MIME type if not identified. media = MediaFileUpload(sdf_path) if not media.mimetype(): media = MediaFileUpload(sdf_filename,'application/octet-stream') # Upload the structured data file. upload_response = service.advertisers().sdfuploadtasks().upload( advertiserId=advertiser_id, body=body, media_body=media ).execute() # Print resulting Operation name. print(f'SDF was successfully uploaded. Operation {upload_response["name"]} was ' 'created to process the uploaded file.')