Interface IReportsClient
Exposes Reports API features for requesting and managing activity reports for your Vonage account.
public interface IReportsClient
Methods
CancelReportAsync(Result<CancelReportRequest>)
Cancels the execution of a pending or processing asynchronous report. Reports that are already completed cannot be cancelled.
Task<Result<ReportResponse>> CancelReportAsync(Result<CancelReportRequest> request)
Parameters
requestResult<CancelReportRequest>The request containing the unique identifier of the report to cancel.
Returns
- Task<Result<ReportResponse>>
A ReportResponse with the final state of the report, or failure if the report was not found or is already in a terminal state.
Examples
var request = CancelReportRequest.Build()
.WithReportId(Guid.Parse("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"))
.Create();
var result = await client.CancelReportAsync(request);
result.Match(
response => Console.WriteLine($"Report status: {response.RequestStatus}"),
failure => Console.WriteLine($"Failed: {failure.GetFailureMessage()}"));
- See Also
CreateReportAsync(Result<CreateReportRequest>)
Creates an asynchronous report generation request. The report is processed in the background; use the returned RequestId with GetReportAsync(Result<GetReportRequest>) to poll for completion.
Task<Result<ReportResponse>> CreateReportAsync(Result<CreateReportRequest> request)
Parameters
requestResult<CreateReportRequest>The request containing the product, account ID, date range, and optional filters.
Returns
- Task<Result<ReportResponse>>
A ReportResponse with the initial report state including the assigned request ID, or failure if required parameters are missing or credentials are invalid.
Examples
var request = CreateReportRequest.Build()
.WithProduct(ReportProduct.Sms)
.WithAccountId("12aa3456")
.WithDateStart(DateTimeOffset.Parse("2024-02-02T00:00:00+00:00"))
.WithDateEnd(DateTimeOffset.Parse("2024-02-07T00:00:00+00:00"))
.WithCallbackUrl(new Uri("https://example.com/webhook"))
.Create();
var result = await client.CreateReportAsync(request);
result.IfSuccess(response => Console.WriteLine($"Report ID: {response.RequestId}"));
- See Also
DownloadReportAsync(Result<DownloadReportRequest>)
Downloads the zipped archive of a completed asynchronous report. The file is available for 72 hours after the report reaches Success. Obtain the file ID from DownloadReport.
Task<Result<Stream>> DownloadReportAsync(Result<DownloadReportRequest> request)
Parameters
requestResult<DownloadReportRequest>The request containing the unique identifier of the file to download.
Returns
- Task<Result<Stream>>
A Stream over the ZIP archive on success, or failure if the file was not found or credentials are invalid. The caller is responsible for disposing the stream.
Examples
var request = DownloadReportRequest.Build()
.WithFileId(Guid.Parse("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"))
.Create();
var result = await client.DownloadReportAsync(request);
result.IfSuccess(async stream =>
{
using var file = File.OpenWrite("report.zip");
await stream.CopyToAsync(file);
});
- See Also
GetReportAsync(Result<GetReportRequest>)
Retrieves the current status and details of an asynchronous report.
Task<Result<ReportResponse>> GetReportAsync(Result<GetReportRequest> request)
Parameters
requestResult<GetReportRequest>The request containing the unique identifier of the report to retrieve.
Returns
- Task<Result<ReportResponse>>
A ReportResponse with the report details and current status, or failure if the report was not found.
Examples
var request = GetReportRequest.Build()
.WithReportId(Guid.Parse("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"))
.Create();
var result = await client.GetReportAsync(request);
result.IfSuccess(response => Console.WriteLine($"Status: {response.RequestStatus}"));
- See Also
LoadRecordsAsync(Result<LoadRecordsRequest>)
Loads records synchronously and returns them immediately. Optimised for frequent retrievals of small batches (up to tens of thousands of records). The response includes HAL navigation links (LoadRecordsHalLink) that can be converted directly into the next request via BuildRequest(), enabling cursor-based pagination without manually reconstructing the query string.
Task<Result<LoadRecordsResponse>> LoadRecordsAsync(Result<LoadRecordsRequest> request)
Parameters
requestResult<LoadRecordsRequest>The request containing the product, account ID, and optional filters.
Returns
- Task<Result<LoadRecordsResponse>>
A LoadRecordsResponse containing the matching records and pagination links, or failure if required parameters are missing or credentials are invalid.
Examples
// Load the first page using the builder:
var firstRequest = LoadRecordsRequest.Build()
.WithProduct(ReportProduct.Sms)
.WithAccountId("12aa3456")
.WithDirection(RecordDirection.Outbound)
.Create();
var firstPage = await client.LoadRecordsAsync(firstRequest);
firstPage.IfSuccess(r => Console.WriteLine($"Records: {r.ItemsCount}"));
// Navigate to the next page directly from the HAL link — no manual URL parsing needed:
var nextPage = await client.LoadRecordsAsync(
firstPage.Bind(response => response.Links.Next.BuildRequest()));
nextPage.IfSuccess(r => Console.WriteLine($"Next page records: {r.ItemsCount}"));
- See Also