Write Data with POST /record#

Apperate’s POST /record endpoint and apperate.write() JS function are fast ways to write one or a few records. By default, they return after storing the data and making it available for querying. Alternatively you can run them asynchronously. When run asynchronously, the call returns immediately to unblock you, Apperate saves the data and makes the data available for query as soon as possible. The async mode facilitates writing to the same dataset simultaneously. Whenever you’re ready to write data, Apperate is ready to store it.

The Write Data reference doc describes the POST /record method and its parameters.

Note

POST /record doesn’t guarantee the ordering of records.

Note

POST /record doesn’t write to any logs. If records fail validation, consider loading the records instead. After attempting to load records, you can view invalid records in the validation logs–See the load options at Loading Data.

Here we’ll write data using the POST /record endpoint.

Write Data#

  1. Prepare a POST /record/ method call. For example, use the following cURL command, replacing the WORKSPACE, DATASET_ID, and SECRET_TOKEN values with your own values and replacing the data (the single-quoted array following -d) with your own JavaScript object array.

    curl -X POST https://WORKSPACE.iex.cloud/v1/record/WORKSPACE/DATASET_ID?token=SECRET_TOKEN \
        -H 'Content-Type: application/json' \
        -d '[{"headline": "Are Hovercrafts the next big thing?", "content": "Here is what people are saying ...", "ticker": "GM", "source": "IEX Underground", "date": "2022-07-15"}]'
    

    Note

    On auto-generating a dataset, Apperate infers a dataset schema from your data; you can update the schema later.

  2. Execute the command.

The method returns a response like the one below and writes the data to the dataset.

{"success":true,"message":"wrote 1 messages"}

To see the data in the dataset go to the Datasets page, click on your Workspace, and refresh the page. Then click on the target dataset’s name. The dataset’s Database page lists its values.

Congratulations! You wrote your data to a dataset using the POST /record endpoint.

What’s Next#

Write and Read Data demonstrates using the apperate.write() JS method.

Update a Dataset Schema shows how to examine and modify your dataset schema.