# Datastore

You can use datastore for use cases like listing active users, managing workspace settings, lookup tables and others. Data from a datastore can be fetched using its name space by a specialist Make module or through API.\
The key specifications for datastore interaction include:

* authentication through Magic Links
* support for CSV data files
* supported text search

The steps below demonstrate an example how to use the datastore functionality and test it with the end-to-end flow:

1. Start with populating a datastore through the **Set a Datastore from a CSV Upload** module in Make. The supported file format for the data is CSV. To pull the CSV file, you can create a scenario in Make with relevant modules.

   For example, for fetching the file you can use the HTTP module and then link it to the **Set a Datastore from a CSV Upload** module.

   * Add a URL to your file in the **HTTP** module.
   * Configure the **Set a Datastore from a CSV Upload**:
     * Add a name for the **Namespace** - it's used for organizing and separating data, it binds the data extracted from the CSV file, for example: `active_users`.
     * Enter the name of the **Key Column**, it's the key for each imported entity, for example: `id`.
     * Select the **HTTP - Get a file** option.
     * Run the scenario, it populates a datastore with all the information from the uploaded file, for example with active users. By default, there are up to 100 entries that are displayed in the response, but the datastore can include more than that.

       <figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-d9a77761205d932342c7a321ea41ed1ce4e0dd64%2Fdatastore_set.png?alt=media" alt=""><figcaption></figcaption></figure>
2. A common use case is to use datastores to populate select boxes in forms - create a form to access the values from the datastore.

   * Go to **Management Dashboard** -> **OE** -> **Forms** and choose **Create form**.
   * Choose the **Dropdown** list component and go to the **Data** tab.
   * Choose **URL** for the **Data Source Type** and paste the URL in the **Data Source URL** field. The variable in the URL is your datastore name from the **Set a Datastore from a CSV Upload** module, for example: `https://api.emporix.io/.../data-store/active_users/values`.
   * Add the **Request Headers**:
     * First - key: `X-Magic-Link`, value: `_MAGIC_LINK_ID_`.
     * Second - key: `X-Tenant`, value: `_TENANT_ID_`.
   * Add the **Search Query Name** - it's used for refining the results, for example: `search`.
   * Leave the **Search Threshold** with the `0,3` value.

   <figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-a5b14fc691792779fddc7111d94f8c27a772a9e9%2Fdatastore_headers.png?alt=media" alt="" width="447"><figcaption></figcaption></figure>
3. Datastores are authenticated with Magic Links. You can add the **Create Form Magic Link ID** module in a Make scenario and in the **Included Forms** select the form that you'd prepared for the datastore search. The module creates a link to the form that is used in the **List Values in a Datastore** module. You can add it in the same scenario or create a new one only for searching the data.

   <figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-5826e797fa061abc9657d58f0e388e8d5d73035f%2Fdatastore_link.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>
4. Add the **List Values in a Datastore** module.

   * Enter the **Namespace** that was set up in the **Set a Datastore from a CSV Upload**, in our example it was `active_users`.
   * Choose the **Magic Link ID** from the **Create Form Magic Link ID** module.
   * Choose the search type, for example, you want to search for users called Nathan.
   * Add a limit for your search, for example, you want to limit the number of active users called Nathan to 250 results.

   <figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-e289c471ed7059b2c30c6b550b24240108512a89%2Fdatastore_search.png?alt=media" alt=""><figcaption></figcaption></figure>
5. Run the scenario. If the run is successful, you can see the search results in bundles, in the **List Values in a Datastore** module output. See the returned demo data:

   <figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-ae3d270a988905913af51b05fe09099baef7803e%2Fdatastore_results.png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}

* The search behaviour is a text match, if the first name is the same as the last name, or a part of it, the search returns results for both.
* Whenever you want to update the stored data, simply upload a new file with the changes. After a new upload, the old data is overridden with new one. To remove all the data, upload an empty file.
  {% endhint %}

The whole example can be viewed in a following flow, but it can be also separated to upload data for the datastore only (with the Get a File and Set a Datastore from a CSV Upload modules), and later to search for data within the configured datastore (with the Create Form Magic Link and List Values in a Datastore modules).

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-9f491f08c0d8a22b22ae8d3150e6d23594b82b6a%2Fdatastore_flow.png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

* To check the Make modules, see the [OE Make Modules](https://developer.emporix.io/oe/value-streams/working-with-value-streams/oe-make-modules) documentation.
* To learn more about forms, see the [Forms](https://developer.emporix.io/oe/management-dashboard/forms) documentation.
  {% endhint %}
