Save Rule Output to a Dataset#

You can persist event data to a dataset for analyzing, auditing, and more. Like all Apperate datasets, it comes with an auto-generated, auto-documented REST endpoint for querying the data.

The image below shows an example dataset of Coinbase event data:

The dataset above has this API endpoint page:

Here we’ll demonstrate how to configure a rule that saves event data and related indexes to a dataset.

Configure Rule Output to a Dataset#

  1. In the Console, click the plus sign next to Rules to start creating a rule. The conditions page appears.

  2. Enter your conditions using the form. Advance to the next screen when you’re done with the conditions. The alerts page appears.

  3. Select Dataset as your alert type and enter the name of your target dataset. If the dataset doesn’t already exist, Apperate creates it on sending the first event output.

    Enter a zero wait time to capture all the matching events.

    In the Additional Indexes section, select facts from other data columns in this or other datasets that you want to output.

    Then advance to the summary page.

  4. When you’re done naming your rule and making configuration changes, click Create Rule. The rule activates.

  5. From the Rules page, you can click on your rule to see its running details.

When events match your rule’s conditions, Apperate writes the event facts and your output indexes to your target dataset.

Tip

When the number Sent is no longer zero in your rule’s running details, your target dataset has rule event output.

Examine the Target Dataset#

Let’s look at the target dataset’s new data.

  1. In the Console under Datasets, click on your workspace name to list your datasets. Your workspace dataset listing appears.

  2. Click on your dataset’s name. The dataset’s database page appears.

    Here is an example target dataset of Coinbase event data.

    Each event has a row for its fact and a row for each additional index fact at that timestamp.

    Note

    All the target dataset columns are type string, except the timestamp column which is date-time.

    Below are the example target dataset properties.

  3. Visit the dataset’s overview page by clicking the Overview tab. The overview appears.

  4. Open the REST endpoint documentation by clicking Open Docs (highlighted in the previous image). The endpoint documentation page appears.

    You can run the example query in your browser and modify it to query what you want.

Let’s consider some things you can do with this data.

What you can do with the data#

Here are just a few things, you an do.

  • Query the data

  • Output data to a CSV file

  • Combine the event data with other data to create custom views

Query the Data#

You can query the target dataset via its REST endpoint. For example, you can click the example endpoint in the endpoint docs page and modify it to fit your needs.

For example, the query below requests the five last (most recent) records.

Query example:

https://api.iex.cloud/v1/data/YOUR_WORKSPACE/YOUR_TARGET_ DATASET?last=5&token=YOUR_API_TOKEN

Example response:

[
  {
    "entity": "BTC_USD_DATASET",
    "fact": "best_ask_size",
    "id": "c6a6056e-efef-4c49-9834-5a97620fb024",
    "namespace": "DATASET",
    "rulename": "Rule BTC-USD at or above xyz",
    "source": "rules",
    "timestamp": "2023-05-08T15:19:50.769Z",
    "value": "0.04701366",
    "workspace": "IEXCLOUDAPPERATE"
  },
  {
    "entity": "BTC_USD_DATASET",
    "fact": "price",
    "id": "c6a6056e-efef-4c49-9834-5a97620fb024",
    "namespace": "DATASET",
    "rulename": "Rule BTC-USD at or above xyz",
    "source": "rules",
    "timestamp": "2023-05-08T15:19:50.769Z",
    "value": "27950.84",
    "workspace": "IEXCLOUDAPPERATE"
  },
  {
    "entity": "BTC_USD_DATASET",
    "fact": "best_ask",
    "id": "c6a6056e-efef-4c49-9834-5a97620fb024",
    "namespace": "DATASET",
    "rulename": "Rule BTC-USD at or above xyz",
    "source": "rules",
    "timestamp": "2023-05-08T15:19:50.769Z",
    "value": "27956.43",
    "workspace": "IEXCLOUDAPPERATE"
  },
  {
    "entity": "BTC_USD_DATASET",
    "fact": "best_bid",
    "id": "c6a6056e-efef-4c49-9834-5a97620fb024",
    "namespace": "DATASET",
    "rulename": "Rule BTC-USD at or above xyz",
    "source": "rules",
    "timestamp": "2023-05-08T15:19:50.769Z",
    "value": "27950.19",
    "workspace": "IEXCLOUDAPPERATE"
  },
  {
    "entity": "BTC_USD_DATASET",
    "fact": "high_24h",
    "id": "c6a6056e-efef-4c49-9834-5a97620fb024",
    "namespace": "DATASET",
    "rulename": "Rule BTC-USD at or above xyz",
    "source": "rules",
    "timestamp": "2023-05-08T15:19:50.769Z",
    "value": "29069.73",
    "workspace": "IEXCLOUDAPPERATE"
  }
]

Output Data to a CSV File#

If you want to output a query response to a .csv file, set the format query parameter to csv (e.g., format=csv in a request URL) in your GET /data request.

Combine Dataset Data to Create Views#

You can join data from your target dataset to data from another dataset to create a view, complete with its own autogenerated API endpoint.

See also

See Create a View for details.

What’s Next#

Create Rules and Alerts Using the API

(Video) Tutorial: Connect to Coinbase and Write a Rule

Querying Datasets

Create a View

Understanding Datasets