Skip to main content

Find a usage-event collection

Find a usage-event collection in the Usage Events list by name. You can also narrow the list with filters and sorting. The list shows the data schema of each usage-event collection.

Prerequisites

  • You need a role with the Can Read Usage Event permission. See Permissions.

Search for a usage-event collection by name

  1. Go to Usage > Usage Events.
  2. In Search Usage Event, enter part of the name.
  3. Select the usage-event collection from the results.
The screen of the usage-event collection opens.

Filter the list

  1. Go to Usage > Usage Events.
  2. Click FILTER.
  3. In Filter by…, select Name, API Slug, or Created At.
  4. Select a condition and a value.
  5. Click APPLY FILTER.
The list shows only the usage-event collections that match. To remove all filters, click Clear All Filters.

Sort the list

  1. Go to Usage > Usage Events.
  2. Click a column header. The list sorts by that column in ascending order.
  3. Click the column header again to sort in descending order.
  4. Click the column header a third time to remove the sorting.
You can sort by every column except S3 Ingestion and S3 Directory.

See the data schema of a usage-event collection

  1. Go to Usage > Usage Events.
  2. In the Data Schema column of the usage-event collection, click View.
The Data Schema window shows the data schema as JSON.

Create a usage-event collection

Create a usage-event collection for each kind of consumption that you record. The name and the API slug of a usage-event collection cannot change after you create it.

Prerequisites

Enter the name and the API slug

  1. Go to Usage > Usage Events.
  2. Click ADD USAGE EVENT. The Add Usage Event screen opens.
  3. In Usage Event Name, enter a name. The name can contain letters, digits, underscores, and spaces.
  4. Under API Slug Endpoint, check the API slug. By default, Follow the usage event name is selected. The API slug then follows the name.
  5. Optional: To choose a different API slug, clear Follow the usage event name. Enter the API slug. The API slug must start and end with a letter or a digit. In between, it can also contain underscores and hyphens.

Turn on S3 ingestion

This step is optional. The screen shows the S3 ingestion options only when the organization has a bucket connection.
  1. Turn on Enable S3 ingestion for this usage event. S3 Directory Name shows the folder that Zenskar reads, after the name of the bucket. By default, the folder is the API slug.
  2. Optional: In Error / DLQ Directory Name, enter an error folder. Use a relative path without a trailing slash. The field shows only when the organization has an ingestion-error bucket.

Define the data schema

You cannot remove or rename a data field after you create the usage-event collection. You cannot change its data type either. Check each data field before you save.
  1. Under Root Fields, check the two root fields, customer_id and timestamp. They cannot change.
  2. Under Your Data Schema, click + ADD NEW DATA FIELD.
  3. In Data field, enter the name of the data field. Zenskar replaces spaces with underscores.
  4. In Data type, select the data type. See Data fields.
  5. Repeat steps 2 to 4 for each data field. To remove a data field before you save, click its delete icon.
  6. Check Data Schema Preview. It shows the data schema as JSON.
  7. Click ADD USAGE EVENT.
Zenskar creates the usage-event collection. The Usage Events list opens.

Fix a failed save

  • Zenskar rejects the usage-event collection when another usage-event collection in the organization has the same API slug. Choose another API slug.
  • Zenskar does not save the usage-event collection when two data fields have the same name. Rename or remove one of them.
  • When creation takes longer than usual, Zenskar finishes it in the background. Check Usage Events again later. If the usage-event collection does not appear, create it again.
  • When Zenskar creates the usage-event collection but cannot turn on S3 ingestion, turn it on from the screen of the usage-event collection. See Set up S3 ingestion for a usage-event collection.

View a usage-event collection

The screen of a usage-event collection shows its API slug endpoint, its data schema, a sample request, and its latest usage events.

Prerequisites

  • You need a role with the Can Read Usage Event permission. See Permissions.

Open the screen of a usage-event collection

  1. Go to Usage > Usage Events.
  2. Click the usage-event collection.
The screen opens with the name of the usage-event collection as its title.

Copy the API slug endpoint

  1. On the screen of the usage-event collection, next to API Slug Endpoint, click the copy icon.
The API slug endpoint is https://api.zenskar.com/usage/ followed by the API slug.

See the data schema

  1. On the screen of the usage-event collection, next to Data Schema, click View.
The Data Schema window shows the data schema as JSON.

Browse the usage events

The Events Table shows the 20 usage events with the latest timestamp. The newest usage event comes first. It has one column for each field of the usage events.
  1. To show usage events that just arrived, click REFRESH TABLE. A usage event can take a few seconds to show.
  2. To narrow the table, click FILTER.
  3. In Filter by…, select a field.
  4. Select a condition and a value. The conditions depend on the data type of the field.
  5. Click APPLY FILTER.
The table shows the 20 latest usage events that match. To remove all filters, click Clear All Filters. To see all matching usage events, download them. See Download usage events.

Send usage events through the API

Send usage events from your systems to the API slug endpoint of a usage-event collection. The screen of the usage-event collection shows a sample request with the API slug endpoint and the headers filled in.

Prerequisites

Copy the sample request

  1. Go to Usage > Usage Events. Click the usage-event collection.
  2. Next to Sample Request, click View. The Sample Request window shows a curl request.
  3. Click the copy icon.
To create an API key from the window, click Create an API Key.

Send a usage event

  1. In the copied request, replace <your-api-key> with your API key. Keep the organisation header. It holds the ID of your organization.
  2. Replace the text after --data-raw with your usage event. Put the root fields at the top level and the data fields inside data. Write timestamp as YYYY-MM-DD HH:MM:SS.
  3. Send the request.
The following request sends one usage event to the usage-event collection with the API slug api_calls:

Send several usage events in one request

  1. In the request, replace the single usage event after --data-raw with a JSON array of usage events.
  2. Send the request.

Add a data field

Add a data field to the data schema of an existing usage-event collection. Usage events that arrived before you add the data field have no value for it.

Prerequisites

  • You need a role with the Can Update Usage Event and Can Read Usage Event permissions. See Permissions.

Add the data field

You cannot remove or rename a data field after you add it. You cannot change its data type either. Check the name and the data type before you submit.
When the name matches a data field that the data schema already has, Zenskar keeps the existing data field and its data type. Zenskar adds nothing. Check the names in Data Schema first.
  1. Go to Usage > Usage Events. Click the usage-event collection.
  2. Click NEW FIELD TO DATA SCHEMA. The section expands.
  3. In Data field name, enter the name. Zenskar replaces spaces with underscores.
  4. In Data field type, select the data type. See Data fields.
  5. Click SUBMIT.
Zenskar adds the data field to the data schema. To close the section without adding a data field, click CANCEL.

Set up S3 ingestion for a usage-event collection

Turn on S3 ingestion for a usage-event collection. Choose the folders that Zenskar uses in the S3 buckets of the organization. Each usage-event collection has its own folder.

Prerequisites

Turn on S3 ingestion

Zenskar reads only the files that arrive in the folder after you turn on S3 ingestion. To read older files, upload them to the folder again after you save.
When the organization has no ingestion-error bucket, Zenskar keeps no record of the files that it rejects. To keep them, add an ingestion-error bucket before you upload files. See Change the bucket connection.
  1. Go to Usage > Usage Events. Click the usage-event collection.
  2. Under S3 Ingestion, turn on the switch. The folder fields open.
  3. In S3 Directory Name, check the folder. It starts as the API slug of the usage-event collection, after the name of the bucket. Use a relative path without a trailing slash, and without . or .. as a part of the path.
  4. Optional: In Error / DLQ Directory Name, enter an error folder. The field shows only when the organization has an ingestion-error bucket.
  5. Click SAVE.

Change the folders

  1. On the screen of the usage-event collection, under S3 Ingestion, click Edit.
  2. Change S3 Directory Name or Error / DLQ Directory Name.
  3. Click SAVE. To discard the change, click CANCEL.
To change the bucket, change the bucket connection. See Change the bucket connection.

Turn off S3 ingestion

Turning off S3 ingestion clears the folder and the error folder of the usage-event collection. To read the folder again, turn S3 ingestion back on. Then enter both folders again.
  1. On the screen of the usage-event collection, under S3 Ingestion, turn off the switch.
Zenskar turns off S3 ingestion right away, without a confirmation. Zenskar stops reading the folder.

Download usage events

Download the usage events of a usage-event collection as a CSV file. You can download all usage events, or only the usage events that match the filters of the Events Table. One download holds at most 50,000 usage events.

Prerequisites

  • You need a role with the Can Read Usage Event permission. See Permissions.

Download the usage events

  1. Go to Usage > Usage Events. Click the usage-event collection.
  2. Optional: Filter the Events Table. See Browse the usage events.
  3. Click DOWNLOAD EVENTS. The Export Events window shows the number of usage events and the expected duration of the download.
  4. If the Events Table has filters, the window lists them under Use filters. Use filters is on. To download all usage events instead, turn off Use filters.
  5. Click EXPORT. Keep the window open until the download finishes.
Your browser saves the file events_export.csv. When the number of usage events is above 50,000, Zenskar does not download them. Add filters until the number is 50,000 or less. Download each part separately.

Upload usage events from a CSV file

Upload a CSV file with one row for each usage event. Zenskar checks every row against the data schema before it stores any row. If one row fails the check, Zenskar stores none of the rows.

Prerequisites

  • You need a role with the Can Create Usage Event and Can Read Usage Event permissions. See Permissions.
  • The CSV file must be at most 100 MB.
  • The CSV file must have one column for each field of the data schema, and no other columns. The column headers are the field names: customer_id, timestamp, and the name of each data field without data. in front, such as endpoint.

Download a sample file

  1. Go to Usage > Usage Events. Click the usage-event collection.
  2. Click UPLOAD CSV. The Upload CSV window opens.
  3. Click Download sample CSV file.
Your browser saves sample.csv. It has the columns that the data schema needs and 100 rows of example values.

Upload the file

  1. On the screen of the usage-event collection, click UPLOAD CSV.
  2. Click Click to upload. Select the file. You can also drag the file into the window.
  3. If the window shows Date Format and Timestamp Format, select the formats that the file uses. The lists show the formats that Zenskar detects in the file.
  4. Optional: To check the rows, click Preview. To download the rows as Zenskar reads them, click Processed CSV.
  5. Click IMPORT CSV DATA. Keep the window open until the upload finishes.
Zenskar stores the usage events. The window closes. A usage event can take a few seconds to show in the Events Table.

Fix a failed upload

  • When the columns do not match the data schema, Zenskar rejects the file before the upload starts. Make the headers match the field names, with one column for each field.
  • When a row fails the check, Zenskar stores none of the rows. Zenskar shows the number of the row. Fix the row. Upload the file again.
  • When the upload stops partway after the check, for example because of a network error, some usage events can already be stored. Check the Events Table before you upload again. A usage event cannot be deleted. A second upload of the same rows stores them twice.

Add a single usage event

Add one usage event from the dashboard, for example to test a usage-event collection.

Prerequisites

  • You need a role with the Can Create Usage Event and Can Read Usage Event permissions. See Permissions.

Add the usage event

  1. Go to Usage > Usage Events. Click the usage-event collection.
  2. Next to UPLOAD CSV, click the arrow. Click Add a single event. The Add New Event panel opens.
  3. In Customer ID, enter the customer ID.
  4. Under Timestamp, in Date, select the date.
  5. In Time, enter the time.
  6. Optional: Enter a value for each data field. The panel shows one entry for each data field, labeled with its name and data type. A Bool data field has True and False. An Int64 data field takes only whole numbers.
  7. Click ADD EVENT.
Zenskar stores the usage event. The panel closes. To close the panel without adding a usage event, click CANCEL.