> For a complete documentation index, fetch https://docs.voximplant.ai/llms.txt

# Key-value storage

Voximplant provides a built-in database for key-value pairs, available throughout the application.

You can store unlimited key-value pairs in the database, your keys can be up to 200 characters string, your values can be up to 2000 characters string.

*You can use the Key-Value Storage module to mask phone numbers, for example, when creating a delivery service solution. An order number can be a key, and a courier's and customer's phone numbers – the values. Thus, the courier and the customer are connected by the order number and do not know each other's phone numbers.*

In this article, we create a simple scenario that “knows” how many times a user calls a number.

## Prerequisites

1. Create [an application](/platform/voxengine/applications).
2. Create [a scenario](/platform/voxengine/scenarios).
3. Create [a routing rule](/platform/voxengine/routing-rules) and attach it to the scenario.
4. Create [a user](/platform/voxengine/users) to log in your client.

You need a working web or mobile application to make calls. Refer to the [Web & Mobile](/getting-started/network-options/web-mobile) guide to learn how to create it.

You can use [our web phone](https://phone.voximplant.com/) to make a call.

## Scenario setup

In the scenario, require the [ApplicationStorage](/api-reference/voxengine/application-storage) module that manages the key-value storage. Use the [put](/api-reference/voxengine/application-storage#put) method to create or update the value and the [get](/api-reference/voxengine/application-storage#get) method to get the current value.

Learn more about the methods in our [API reference](/api-reference/voxengine/application-storage).

Take a look at the scenario code for our task:

**`Scenario code`**

```javascript title="Scenario code"
require(Modules.ApplicationStorage);

const storageTTL = { day: 86400, week: 604800 };

VoxEngine.addEventListener(AppEvents.CallAlerting, async (e) => {
  let current = 0;
  try {
    const res = await ApplicationStorage.get('totalCalls');
    if (!res || res.value === null) {
      await ApplicationStorage.put('totalCalls', '0', storageTTL.week);
      current = 0;
    } else {
      current = Number(res.value) || 0;
    }
  } catch (err) {
    Logger.write('Failure while getting totalCalls value: ' + err);
  }

  // increase counter
  const next = current + 1;
  try {
    await ApplicationStorage.put('totalCalls', String(next), storageTTL.week);
  } catch (err) {
    Logger.write('Failure while updating totalCalls value: ' + err);
  }
  e.call.answer();
  e.call.say(
    `Hello. You have called ${next} times`,
    { voice: VoiceList.Amazon.en_US_Joanna }
  );
  e.call.addEventListener(CallEvents.PlaybackFinished, VoxEngine.terminate);
});

```

We declare a variable to make a comparison between a call counter and the initial value possible. Then we try to retrieve the **totalCalls** value from the application storage. If there is no value, we create such a variable in the storage:

**`Compare the call counter and the initial value`**

```javascript title="Compare the call counter and the initial value"
const res = await ApplicationStorage.get('totalCalls');
if (!res || res.value === null) {
  await ApplicationStorage.put('totalCalls', '0', storageTTL.week);
  current = 0;
} else {
  current = Number(res.value) || 0;
}

```

The next action to perform is to increment the value in the storage.

**`Increment the value`**

```javascript title="Increment the value"
// increase counter
const next = current + 1;
try {
  await ApplicationStorage.put('totalCalls', String(next), storageTTL.week);
} catch (err) {
  Logger.write('Failure while updating totalCalls value: ' + err);
}

```

> **Pay attention**
>
> Each promise rejection should be handled as has been shown in the example above, otherwise, your scenario fails during the execution. See the details [here](https://voximplant.com/blog/cloud-side-javascript-promise-handling-update).

After working with the storage, the scenario answers a call with a synthesized message of how many times you called before. When the [robotic speech](https://voximplant.com/blog/what-is-rpa-technology) is over, the scenario terminates a call session.

## Test your application

Open [https://phone.voximplant.com/](https://phone.voximplant.com/) and log in with your credentials. After successful login, enter an arbitrary string and click **Call**. If everything goes properly, you hear a synthesized greeting!