日付の範囲で同期的にレコードを取得する

このコード・スニペットは、日付範囲を使ってレコード・セットを取得する方法を示しています。これは同期呼び出しなので、レスポンスを返すまでブロックされます。限られた数のレコード(Numbers)をすぐに返したい場合に使用します。大量のレコード(数百万件)を取得したい場合は レポート作成.

同期クエリでは、日付範囲は24時間のウィンドウに制限されます。

キー説明
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.

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.

Write the code

Add the following to load-records-sync-dates.sh:

curl -G --data-urlencode date_start=$DATE_START --data-urlencode date_end=$DATE_END -u "$VONAGE_API_KEY:$VONAGE_API_SECRET" \
     "https://api.nexmo.com/v2/reports/records?account_id=$ACCOUNT_ID&product=$REPORT_PRODUCT&direction=$REPORT_DIRECTION"

View full source

Run your code

Save this file to your machine and run it:

bash load-records-sync-dates.sh

試してみる

  1. アカウントの交換可能な変数を設定します。

  2. この例では REPORT_PRODUCT への SMS.

  3. 表を参考に、残りの変数の値を設定する。

  4. スクリプトを実行すると、次のような応答が返ってくる:

{
  "_links": {
    "self": {
      "href": "https://api.nexmo.com/v2/reports/records?account_id=abcd1234&product=SMS&direction=outbound&date_start=2020-06-04T08%3A00%3A00Z&date_end=2020-06-04T14%3A00%3A00Z&status=delivered"
    }
  },
  "request_id": "450b434a-ff4f-40f1-80a5-8d6e24d91234",
  "request_status": "SUCCESS",
  "received_at": "2020-06-04T12:22:25+0000",
  "price": 0.0,
  "currency": "EUR",
  "direction": "outbound",
  "product": "SMS",
  "account_id": "abcd1234",
  "date_start": "2020-06-04T08:00:00+0000",
  "date_end": "2020-06-04T14:00:00+0000",
  "include_subaccounts": false,
  "status": "delivered",
  "include_message": false,
  "items_count": 2,
  "records": [
    {
      "account_id": "abcd1234",
      "message_id": "12000000E506AC66",
      "client_ref": null,
      "direction": "outbound",
      "from": "Acme Inc.",
      "to": "447700123456",
      "network": "23410",
      "network_name": "Telefonica UK Limited",
      "country": "GB",
      "country_name": "United Kingdom",
      "date_received": "2020-06-04T12:21:35+0000",
      "date_finalized": "2020-06-04T12:21:37+0000",
      "latency": "2274",
      "status": "delivered",
      "error_code": "0",
      "error_code_description": "Delivered",
      "currency": "EUR",
      "total_price": "0.03330000"
    },
    ...
  ]
}

参照