You can create an Interactive report, run an existing report, and read report results using the Ad Manager API.
If you are unfamiliar with Interactive reporting in Ad Manager, see Create an Interactive report for an overview of how to use Interactive reports in the Ad Manager UI.
For complex reports, you can use the Ad Manager UI to check dimension and metric compatibility. All UI reports can be run with the API.
This guide covers how to initiate an asynchronous run of a Report
,
poll the returned Operation
status, obtain the Result
resource name from the completed Operation
and fetch a paginated set of result Rows
.
Prerequisite
Before continuing, ensure you have access to a Google Ad Manager network. To get access, see Get started with Google Ad Manager .
Run a report
To run a report, you need the report ID. You can obtain a report ID in the Ad
Manager UI through the report URL. For example, in the URL https://admanager.google.com/234093456#reports/interactive/detail/report_id=4555265029
the report ID is 4555265029
.
You can also read reports your user has access to using the networks.reports.list
method and get the ID from the resource name:
networks/234093456/reports/4555265029
After you have your report ID, you can initiate an asynchronous run of the
report using the networks.reports.run
method. This method returns the resource name of a long running Operation
.
Note that in the following example code, REPORT_ID
is a placeholder for the
report ID and NETWORK_CODE
is a placeholder for your network code. To find
you network code, see Find Ad Manager account information
.
Java
import
com.google.ads.admanager.v1.ReportName
;
import
com.google.ads.admanager.v1.ReportServiceClient
;
import
com.google.ads.admanager.v1.RunReportResponse
;
public
class
SyncRunReportReportname
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
syncRunReportReportname
();
}
public
static
void
syncRunReportReportname
()
throws
Exception
{
try
(
ReportServiceClient
reportServiceClient
=
ReportServiceClient
.
create
())
{
ReportName
name
=
ReportName
.
of
(
" NETWORK_CODE
"
,
" REPORT_ID
"
);
RunReportResponse
response
=
reportServiceClient
.
runReportAsync
(
name
).
get
();
}
}
}
Python
from google.ads import admanager_v1 def sample_run_report (): # Create a client client = admanager_v1 . ReportServiceClient () # Initialize request argument(s) request = admanager_v1 . RunReportRequest ( name = "networks/ NETWORK_CODE /reports/ REPORT_ID " , ) # Make the request operation = client . run_report ( request = request ) print ( "Waiting for operation to complete..." ) response = operation . result () # Handle the response print ( response )
.NET
using
Google.Ads.AdManager.V1
;
using
Google.LongRunning
;
public
sealed
partial
class
GeneratedReportServiceClientSnippets
{
public
void
RunReportResourceNames
()
{
// Create client
ReportServiceClient
reportServiceClient
=
ReportServiceClient
.
Create
();
// Initialize request argument(s)
ReportName
name
=
ReportName
.
FromNetworkCodeReport
(
" NETWORK_CODE
"
,
" REPORT_ID
"
);
// Make the request
Operation<RunReportResponse
,
RunReportMetadata
>
response
=
reportServiceClient
.
RunReport
(
name
);
// Poll until the returned long-running operation is complete
Operation<RunReportResponse
,
RunReportMetadata
>
completedResponse
=
response
.
PollUntilCompleted
();
// Retrieve the operation result
RunReportResponse
result
=
completedResponse
.
Result
;
// Or get the name of the operation
string
operationName
=
response
.
Name
;
// This name can be stored, then the long-running operation retrieved later by name
Operation<RunReportResponse
,
RunReportMetadata
>
retrievedResponse
=
reportServiceClient
.
PollOnceRunReport
(
operationName
);
// Check if the retrieved long-running operation has completed
if
(
retrievedResponse
.
IsCompleted
)
{
// If it has completed, then access the result
RunReportResponse
retrievedResult
=
retrievedResponse
.
Result
;
}
}
}