非同期にレポートを作成する

このコード・スニペットは、日付範囲を使ってレポートを非同期に生成する方法を示しています。

これは非同期呼び出しなので、すぐに返される。レポート生成の現在のステータスは レポート・ステータスの取得.完了したら、次の方法でレポートを入手できます。 レポートを入手する.あるいは、コールバックURLを設定して、レポート生成が完了したときに通知を受け取ることもできる。

このコールでは、日付の範囲は13カ月に制限されている。

キー説明
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'"
}'

View full source

Run your code

Save this file to your machine and run it:

bash create-async-report.sh

試してみる

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

  2. この例では REPORT_PRODUCT のいずれかに SMS, VOICE または MESSAGES.

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

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

{
  "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"
    }
  }
}

コールバックURLを設定すると、前のステップで示したのと同じ内容のコールバックがそのURLに届きます。

参照