Bits
Bits

Reputation: 276

Google DV360 Reporting - Error while fetching performance metrics

I am trying to extract and download reports from DV360 API using python. I have gone through the documentation https://developers.google.com/bid-manager/guides/get-started/send-request ,but not able to fetch the performance metrics like impressions,clicks,revenue. I have tried the below code,

from google.oauth2 import service_account
from googleapiclient.discovery import build

# Replace with the path to your service account key file
SERVICE_ACCOUNT_FILE = "service_account.json"

# Define the required scopes
SCOPES = ['https://www.googleapis.com/auth/display-video']

# Authenticate using the service account
credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE, scopes=SCOPES)

# Initialize the DV360 API client
service = build('displayvideo', 'v3', credentials=credentials)

# Define the query parameters
query = {
    "metadata": {
        "title": "KPI_Report",
        "dataRange": {"range": "LAST_30_DAYS"},
        "format": "CSV"
    },
    "params": {
        "type": "STANDARD",
        "groupBys": [
            "FILTER_DATE",
            "FILTER_PLATFORM",
            "FILTER_MONTH",
            "FILTER_YEAR",
            "FILTER_ADVERTISER_NAME",
            "FILTER_CAMPAIGN_NAME",
            "FILTER_MEDIA_TYPE"
        ],
        "metrics": [
            "METRIC_IMPRESSIONS",
            "METRIC_CLICKS",
            "METRIC_TOTAL_CONVERSIONS",
            "METRIC_MEDIA_COST_ADVERTISER",
            "METRIC_GMAIL_CLICKS",
            "METRIC_CTR",
            "METRIC_CPM",
            "METRIC_CPC",
            "METRIC_CPV",
            "METRIC_CR",
            "METRIC_VIEWS",
            "METRIC_VTR",
            "METRIC_COMPLETE_VIDEO_VIEWS",
            "METRIC_COMPLETE_VIEW_RATE",
            "METRIC_CPCV",
            "METRIC_RICH_MEDIA_ENGAGEMENTS",
            "METRIC_FREQUENCY",
            "METRIC_REACH"
        ],
        "filters": [
            {"type": "FILTER_ADVERTISER", "value": "YOUR_ADVERTISER_ID"}
        ]
    },
    "schedule": {"frequency": "ONE_TIME"}
}

# Create the query
query_response = service.queries().create(body=query).execute()
query_id = query_response.get('queryId')

print (query_id)

I'm receiving the following error as AttributeError: 'Resource' object has no attribute 'queries'

Can anyone please help me to get this? Is there a way to fetch these metrics using DV360 API.

Upvotes: 2

Views: 103

Answers (1)

dikesh
dikesh

Reputation: 3125

The method you are calling to create report is not correct. In order to create report in DV360 you need to call create method of query as below.

response = service.queries().create(body=body).execute()
print(response.get('queryId'))

Checkout the example as shown in this guide and reference document for create method.

Upvotes: -1

Related Questions