Obter registros específicos por UUID

Este trecho de código mostra como recuperar um registro específico, especificando um mensagem ou ligação UUID. Também é possível especificar uma lista de UUIDs separados por vírgulas para recuperar vários registros, por exemplo:

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

Se não forem encontrados registros correspondentes a nenhum dos UUIDs especificados, uma lista desses UUIDs será retornada na resposta por meio do ids_not_found campo, por exemplo:

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

NOTA: Esta é uma chamada síncrona e, portanto, ficará bloqueada até que retorne uma resposta.

Exemplo

ChaveDescrição
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.

Escreva o código

Adicione o seguinte ao arquivo ` 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 código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

bash load-records-sync-id.sh

Pré-requisitos

Install-Package Vonage

Crie um arquivo chamado ` LoadsRecordsByUUID.cs ` e insira o seguinte código:

var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
Client = new VonageClient(credentials);

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao arquivo ` LoadsRecordsByUUID.cs`:

var request = LoadRecordsRequest.Build()
    .WithProduct(product)
    .WithAccountId(accountId)
    .WithDirection(direction)
    .WithId(id)
    .Create();
var response = await Client.ReportsClient.LoadRecordsAsync(request);

Ver código-fonte completo

Experimente

  1. Defina as variáveis substituíveis para sua Account.

  2. Para este exemplo, defina REPORT_PRODUCT para SMS.

  3. Usando a tabela como orientação, defina os valores para as variáveis restantes.

  4. Execute o script e você receberá uma resposta semelhante à seguinte:

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

Veja também