Obtener registros específicos por UUID

Este fragmento de código muestra cómo recuperar un registro específico especificando una variable mensaje o llamada UUID. También es posible especificar una lista de UUID separados por comas para recuperar varios registros, por ejemplo:

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

Si no se encuentran los registros correspondientes a alguno de los UUID especificados, se devuelve una lista de los mismos en la respuesta utilizando la función ids_not_found por ejemplo:

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

NOTA: Se trata de una llamada sincrónica, por lo que se bloqueará hasta que devuelva una respuesta.

Ejemplo

ClaveDescripción
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.

Escriba el código

Añada lo siguiente a 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"

Ver fuente completa

Ejecute su código

Guarde este archivo en su máquina y ejecútelo:

bash load-records-sync-id.sh

Pruébalo

  1. Establezca las variables reemplazables para su Account.

  2. Para este ejemplo, configure REPORT_PRODUCT a SMS.

  3. Utilizando la tabla como guía, establezca los valores para el resto de variables.

  4. Ejecute el script y recibirá una respuesta similar a la siguiente:

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

Ver también