Create report asynchronously
This code snippet shows you how to generate a report asynchronously, using a date range.
This is an asynchronous call and so will return immediately. You can check the current status of report generation with Get Report Status. Once completed, you can obtain the report with Get Report. Alternatively, you can set a callback URL and receive a notification when report generation is complete.
Date range is limited to 13 months for this call.
Example
Key | Description |
---|---|
VONAGE_API_KEY |
Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET |
Your Vonage API secret (also available on your dashboard). |
ACCOUNT_ID |
The account ID (same as VONAGE_API_KEY ) for the account you want to generate reports, or retrieve records for. |
REPORT_DIRECTION |
Either inbound or outbound
|
REPORT_PRODUCT |
Specifies the product for which reports and records are obtained. Can be one of SMS , VOICE-CALL , WEBSOCKET-CALL , VERIFY-API , NUMBER-INSIGHT , MESSAGES , CONVERSATIONS , or ASR . |
REQUEST_ID |
The request ID returned when a report was created |
DATE_START |
Date of time window from when you want to start gathering records in ISO-8601 format. |
DATE_END |
Date of time window from when you want to stop gathering records in ISO-8601 format. |
STATUS |
Status of message or call. |
Write the code
Add the following to create-async-report.sh
:
curl -X POST "https://api.nexmo.com/v2/reports" \
-H 'Content-Type: application/json; charset=utf-8' \
-u "$VONAGE_API_KEY:$VONAGE_API_SECRET" \
-d $'{
"product": "$REPORT_PRODUCT",
"account_id": "$ACCOUNT_ID",
"direction": "$REPORT_DIRECTION",
"status": "$STATUS",
"date_start": "$DATE_START",
"date_end": "$DATE_END"
}'
Run your code
Save this file to your machine and run it:
bash create-async-report.sh
Try it out
Set the replaceable variables for your account.
For this example, set
REPORT_PRODUCT
to one ofSMS
,VOICE
orMESSAGES
.Using the table as a guide set values for the remaining variables.
Run the script and you receive a response similar to the following:
{
"request_id": "ri3p58f-42d57cfd-1234-5678-9abc-67580d95f54a",
"request_status": "PENDING",
"direction": "outbound",
"product": "SMS",
"account_id": "abcd1234",
"date_start": "2020-05-21T13:27:00+0000",
"date_end": "2020-05-21T13:57:00+0000",
"include_subaccounts": false,
"include_message": false,
"receive_time": "2020-06-04T10:53:32+0000",
"_links": {
"self": {
"href": "https://api.nexmo.com/v2/reports/ri3p58f-42d57cfd-1234-5678-9abc-67580d95f54a"
}
}
}
If you set a callback URL, you will receive a callback on that URL with the same content as shown in the previous step.