这份文档还在翻译中,预期年底前完成。欢迎您提供宝贵的意见及建议。

List reports

This code snippet shows you how to list all asynchronous report requests with the specified status. If required, you can also specify a date range.

Example

Variable Required Description
NEXMO_API_KEY Yes Your API key which you can obtain from your Dashboard.
NEXMO_API_SECRET Yes Your API secret which you can obtain from your Dashboard.
ACCOUNT_ID Yes The API key for the target account. Reports generated, or records retrieved, are for this account.
REPORT_STATUS Yes A comma-separated list of report status values. Reports with any of the statuses specified are returned. The values in the comma-separated list specified for status can be any of PENDING, PROCESSING, SUCCESS, ABORTED, FAILED, TRUNCATED.

If you don't specify a date range, you receive the reports generated over the previous seven days.

Write the code

Add the following to list-reports.sh:

Copy to Clipboard
curl -u "$NEXMO_API_KEY:$NEXMO_API_SECRET" \
     "https://api.nexmo.com/v2/reports?account_id=$ACCOUNT_ID&status=$REPORT_STATUS"

View full source

Run your code

Save this file to your machine and run it:

bash list-reports.sh

Try it out

  1. Set the replaceable variables. Parameter validity may vary with product.

  2. Run the script and you receive a response similar to the following:

{
  "self_link": "https://api.nexmo.com/v2/reports?account_id=abcd1234&status=SUCCESS",
  "items_count": 17,
  "reports": [
    {
      "request_id": "ri3p58f-48598ea7-1234-5678-90ab-faabd79abcde",
      "request_status": "SUCCESS",
      "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,
      "status": "delivered",
      "include_message": false,
      "receive_time": "2020-06-03T15:24:31+0000",
      "start_time": "2020-06-03T15:24:32+0000",
      "_links": {
        "self": {
          "href": "https://api.nexmo.com/v2/reports/ri3p58f-48598ea7-1234-5678-90ab-faabd79abcde"
        },
        "download_report": {
          "href": "https://api.nexmo.com/v3/media/e87a2d7c-abcd-1234-aa45-9bf17a1eb2a1"
        }
      },
      "items_count": 4
    },
    ...
  ]
}

Note the report request_id is in the response. Also the file_id, in this case e87a2d7c-abcd-1234-aa45-9bf17a1eb2a1.

See also