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, gcp_conn_id 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.

Getting a Query

To retrieve a query using Bid Manager, use GoogleBidManagerGetQueryOperator.

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

get_query = GoogleBidManagerGetQueryOperator(query_id=query_id, task_id="get_query", gcp_conn_id=CONN_ID)

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

Listing Queries

To list queries using Bid Manager, use GoogleBidManagerListQueriesOperator.

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

list_queries = GoogleBidManagerListQueriesOperator(task_id="list_queries", gcp_conn_id=CONN_ID)

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

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, gcp_conn_id parameters which allow you to dynamically determine values. The result is saved to XCom, which allows the result to be used by other operators.

Getting a Report

To retrieve a report using Bid Manager, use GoogleBidManagerGetReportOperator.

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

get_report = GoogleBidManagerGetReportOperator(
    query_id=query_id,
    report_id=report_id,
    task_id="get_report",
    gcp_conn_id=CONN_ID,
)

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

Listing Reports

To list reports for a query using Bid Manager, use GoogleBidManagerListReportsOperator.

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

list_reports = GoogleBidManagerListReportsOperator(
    query_id=query_id,
    task_id="list_reports",
    gcp_conn_id=CONN_ID,
)

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

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, gcp_conn_id 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, gcp_conn_id 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]

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

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

Was this entry helpful?