UUIDで特定のレコードを取得する

このコード・スニペットは、特定のレコードを取得する方法を示しています。 メッセージまたは電話 UUID。カンマ区切りのUUIDリストを指定して、複数のレコードを検索することも可能である:

curl -u "$VONAGE_API_KEY:$VONAGE_API_SECRET" https://api.nexmo.com/v2/reports/records?account_id=abcd1234&product=VERIFY-API&id=7b1091b8-1a05-11eb-bad9-38f9d331493,7b109636-1a05-11eb-bad9-38f9d3316493,7b109a1e-1a05-11eb-bad9-38f9d3316493,7b10a0c2-1a05-11eb-bad9-38f9d331649

指定されたUUIDのいずれかに対応するレコードが見つからない場合は、そのリストが ids_not_found フィールドのようなものだ:

{
...
  "ids_not_found": "7b10a0c2-1a05-11eb-bad9-38f9d331649,7b1091b8-1a05-11eb-bad9-38f9d331493"
...
}

注: これは同期呼び出しなので、応答を返すまでブロックされる。

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

ID

The UUID of the message or call to retrieve a record for. It is possible to specify a comma-separated list of UUIDs to retrieve multiple records.

Write the code

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

curl -u "$VONAGE_API_KEY:$VONAGE_API_SECRET" \
     "https://api.nexmo.com/v2/reports/records?account_id=$ACCOUNT_ID&product=$REPORT_PRODUCT&direction=$REPORT_DIRECTION&id=$ID"

View full source

Run your code

Save this file to your machine and run it:

bash load-records-sync-id.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&id=15000000E1F8B123"
        }
    },
    "request_id": "0ec00351-5357-4321-9a08-fa3d4a4e1234",
    "request_status": "SUCCESS",
    "id": "15000000E1F8B123",
    "received_at": "2020-06-04T11:55:42+0000",
    "price": 0.0,
    "currency": "EUR",
    "account_id": "abcd1234",
    "product": "SMS",
    "direction": "outbound",
    "include_message": false,
    "items_count": 1,
    "records": [
        {
            "account_id": "abcd1234",
            "message_id": "15000000E1F8B123",
            "client_ref": null,
            "direction": "outbound",
            "from": "Vonage APIs",
            "to": "447700123456",
            "network": "23410",
            "network_name": "Telefonica UK Limited",
            "country": "GB",
            "country_name": "United Kingdom",
            "date_received": "2020-06-01T15:08:10+0000",
            "date_finalized": "2020-06-01T15:08:11+0000",
            "latency": "1366",
            "status": "delivered",
            "error_code": "0",
            "error_code_description": "Delivered",
            "currency": "EUR",
            "total_price": "0.03330000"
        }
    ]
}

参照