Crear informe de forma asíncrona

Este fragmento de código muestra cómo generar un informe de forma asíncrona, utilizando un intervalo de fechas.

Se trata de una llamada asíncrona, por lo que se completará de forma inmediata. Puedes comprobar el estado actual de la generación del informe con Consultar el estado del informe. Una vez completado, puedes obtener el informe con Obtener informe. Como alternativa, puede establecer una URL de devolución de llamada y recibir una notificación cuando se complete la generación del informe.

El plazo de esta convocatoria se limita a 13 meses.

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.

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.

Escriba el código

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

Ver fuente completa

Ejecute su código

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

bash create-async-report.sh

Requisitos previos

Install-Package Vonage

Crea un archivo llamado CreateReport.cs y añade el siguiente código:

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

Ver fuente completa

Escriba el código

Añada lo siguiente a CreateReport.cs:

var request = CreateReportRequest.Build()
    .WithProduct(product)
    .WithAccountId(accountId)
    .WithDirection(direction)
    .WithDateStart(dateStart)
    .WithDateEnd(dateEnd)
    .WithStatus(status)
    .Create();
var response = await Client.ReportsClient.CreateReportAsync(request);

Ver fuente completa

Pruébalo

  1. Establezca las variables reemplazables para su Account.

  2. Para este ejemplo, configure REPORT_PRODUCT a uno de SMS, VOICE o MESSAGES.

  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:

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

Si establece una URL de devolución de llamada, recibirá una devolución de llamada en esa URL con el mismo contenido que se muestra en el paso anterior.

Véase también