Google Bid Manager API Operators

Google Bid Manager API is a programmatic interface for the Display & Video 360 reporting feature. It lets users build and run report queries, and download the resulting report file.

Prerequisite Tasks

To use these operators, you must do a few things:

Creating a Query

To create a query using Bid Manager, use GoogleBidManagerCreateQueryOperator.

tests/system/google/marketing_platform/example_bid_manager.py[source]

create_query = GoogleBidManagerCreateQueryOperator(
    body=REPORT, task_id="create_query", gcp_conn_id=CONN_ID
)

query_id = cast("str", XComArg(create_query, key="query_id"))

Use Jinja templating with body, impersonation_chain parameters which allow you to dynamically determine values. You can provide body definition using .json file as this operator supports this template extension. The result is saved to XCom, which allows the result to be used by other operators.

Run Query

To run a query using Bid Manager, use GoogleBidManagerRunQueryOperator.

tests/system/google/marketing_platform/example_bid_manager.py[source]

run_query = GoogleBidManagerRunQueryOperator(
    query_id=query_id, parameters=PARAMETERS, task_id="run_report", gcp_conn_id=CONN_ID
)

query_id = cast("str", XComArg(run_query, key="query_id"))
report_id = cast("str", XComArg(run_query, key="report_id"))

You can use Jinja templating with query_id, parameters, impersonation_chain parameters which allow you to dynamically determine values. The result is saved to XCom, which allows the result to be used by other operators.

Deleting a Query

To delete a query using Bid Manager, use GoogleBidManagerDeleteQueryOperator.

tests/system/google/marketing_platform/example_bid_manager.py[source]

delete_query = GoogleBidManagerDeleteQueryOperator(
    query_id=query_id, task_id="delete_query", trigger_rule=TriggerRule.ALL_DONE, gcp_conn_id=CONN_ID
)

You can use Jinja templating with query_id, impersonation_chain parameters which allow you to dynamically determine values.

Waiting for query

To wait for the report use GoogleBidManagerRunQuerySensor.

tests/system/google/marketing_platform/example_bid_manager.py[source]

wait_for_query = GoogleBidManagerRunQuerySensor(
    task_id="wait_for_query",
    query_id=query_id,
    report_id=report_id,
    gcp_conn_id=CONN_ID,
)

Use Jinja templating with query_id, report_id, impersonation_chain parameters which allow you to dynamically determine values.

Downloading a report

To download a report to GCS bucket use GoogleBidManagerDownloadReportOperator.

tests/system/google/marketing_platform/example_bid_manager.py[source]

get_report = GoogleBidManagerDownloadReportOperator(
    query_id=query_id,
    report_id=report_id,
    task_id="get_report",
    bucket_name=BUCKET_NAME,
    report_name="test1.csv",
    gcp_conn_id=CONN_ID,
)

delete_bucket = GCSDeleteBucketOperator(
    task_id="delete_bucket",
    bucket_name=BUCKET_NAME,
    gcp_conn_id=CONN_ID,
    trigger_rule=TriggerRule.ALL_DONE,
)

Use Jinja templating with query_id, report_id, bucket_name, report_name, impersonation_chain parameters which allow you to dynamically determine values.

Was this entry helpful?