Get audit events with filtering

In this building block you see how to get a list of audit events with filtering.

Parameters

You can filter the list of event objects returned by using query parameters. The parameters that can be specified are shown in the following table:

Query Parameter Description
event_type The type of the audit event, for example: APP_CREATE, NUMBER_ASSIGN, and so on. You can specify a comma-delimited list of event types here.
search_text JSON compatible search string. Look for specific text in an audit event.
date_from Retrieve audit events from this date (in ISO-8601 format).
date_to Retrieve audit events to this date (in ISO-8601 format).
page Page number starting with page 1.
size Number of elements per page (between 1 and 100, default 30).

Example

You will need to ensure that the following replaceable values are set in the example code using any convenient method:

Key Description
NEXMO_API_KEY Your Nexmo API key.
NEXMO_API_SECRET Your Nexmo API secret.
SEARCH_TEXT Some JSON compatible text to search for, for example "number".
DATE_FROM Audit events starting from this ISO-8601 datetime value. For example, "2018-07-01".
DATE_TO Audit events up to this ISO-8601 datetime value. For example, "2018-08-01"

In the following example the Create an application and Initialize your dependencies procedures are optional.

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI  (see below) or via the dashboard  . To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok  to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Get Events with filtering"  http://demo.ngrok.io/webhooks/events --keyfile private.key
Initialize your dependencies

Create a file named get-events-with-filtering.sh and add the following code:

Copy to Clipboard
source "../config.sh"

View full source 

Write the code

Add the following to get-events-with-filtering.sh:

Copy to Clipboard
curl "https://api.nexmo.com/beta/audit/events?search_text=$SEARCH_TEXT&date_from=$DATE_FROM&date_to=$DATE_TO" \
     -u "$NEXMO_API_KEY:$NEXMO_API_SECRET"

View full source 

Run your code

Save this file to your machine and run it:

$ ./get-events-with-filtering.sh

Try it out

Run the command in a shell. The call will retrieve a filtered list of audit events.