# How to use the Vault

The Integration Gateway vault feature provides a way for configuration, secrets, and state to be read and written by integrations.

More specifically, it is an API for storing and retrieving JSON in the database, as well as a page in the Integration Gateway application to manage the stored content.

Some useful vault vocabulary:

* A "Vault Item" is a JSON object with a name, it can be read or written by integrations, as well as on the vault page.
* A "Vault Secret" is like a Vault Item, except that it cannot be read on the vault page, only written.
* A "Vault" is a named collection of Vault Items and Secrets

**This guide will explain how to:**

1. Create a vault
2. Create a vault item
3. Configure your integration to have access to the vault
4. Read the vault item in an integration hook

Prerequisites:

* This guide expects you are familiar with the build page and editing integrations
* You must be a superuser or have the "can view vault" permission

## Creating a Vault

First, you must create a "Vault". This allows for your items and secrets to be logically organized.

1\) Navigate to the vault page by clicking the vault icon on the sidebar: ![](https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2Fdng9hKgiJotpwvUq0vH7%2Fimage.png?alt=media\&token=b28fc693-53c5-4f70-b1bf-61854fd0c0e2)

2\) Press the "+ Create Vault" button ![](https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FJYLcxokVFQ0cskPiYIQd%2Fimage.png?alt=media\&token=3cbf4f92-8322-425d-a9c2-7885bee0d487)

3\) Name your vault "my-vault" in the modal , then press "Create Vault"

<figure><img src="https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FcSyPBAhZJg0i1lzXiX5R%2Fimage.png?alt=media&#x26;token=11115163-e995-495a-b0c8-14edbcb0ca48" alt=""><figcaption></figcaption></figure>

## Creating a Vault Item

Next, we'll create an item in the vault. This is the item your integration will read at runtime.

1\) Select "my-vault" in the leftmost column

2\) Press "+ Create Vault Item" ![](https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FHEgvqZQM4b2b4hkOOxh2%2Fimage.png?alt=media\&token=84ac54dc-770a-4b9c-bcad-f3313588fa85)

3\) In the modal, provide the name "my-item" for your vault item, and in the text editor, provide some valid JSON.

<figure><img src="https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FRO2E37veu4WhIUIKAHEO%2Fimage.png?alt=media&#x26;token=e867ad13-caf6-4c4b-9d8c-30a57a7d9773" alt=""><figcaption></figcaption></figure>

4\) Press "+ Create Vault Item"

You vault item is now saved, and can be seen on the vault page

<figure><img src="https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FqGcijUFyQZm3otgezCeR%2Fimage.png?alt=media&#x26;token=0b006a0f-ffdd-4d1f-997a-2d66fdb1d0fd" alt=""><figcaption></figcaption></figure>

## Connecting your integration to the Vault

This step assumes you have an existing integration called "my-integration"

1\) Navigate to the admin page by pressing the profile icon on the top-right of Integration Gateway and select "Admin"

![](https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FUuYoPkni17GMcZs9sasa%2Fimage.png?alt=media\&token=e1954453-3085-438b-b0de-b11f35e6c8dd)

2\) On the page that appears, scroll to and click on "+ Add" next to "Vault Permissions"

<figure><img src="https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FlGB99ZEkONWHc8Pl8M3f%2Fimage.png?alt=media&#x26;token=671c9efc-e874-4528-8d1b-a3bde4f681a1" alt=""><figcaption></figcaption></figure>

3\) Fill out the form to give "my-integration" permission to read from "my-vault"

<figure><img src="https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FDLSmnnGpCTLpv2QyMAAy%2Fimage.png?alt=media&#x26;token=c2dc0bd7-a7ad-4bff-ae1e-842a3b6a893c" alt=""><figcaption></figcaption></figure>

4\) Press save

5\) Return to the Integration Gateway Application by pressing "View Site" on the top-right corner of your screen

<figure><img src="https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2Fc64h5AL5Eak2c0bvsSF8%2Fimage.png?alt=media&#x26;token=bf2e959b-5c88-497d-93e5-06d630068237" alt=""><figcaption></figcaption></figure>

## Read the vault within your integration

First - some important concepts about the vault:

A given vault can only be opened by one running integration at a time. If another integration tries to open a vault that is already open, it will halt until the other running integration closes it.

For this reason, it is important to always close a vault when you are done using it. We make this easy by providing a vault context manager (The python 'with' statement)

Here is the code we will be putting into our integration before hook:

```python
with open_vault('my-vault') as vault:
    my_data = vault.get("my-item")
# The with statement automatically closes the vault at this point
debug(my_data, label="Here's what was in the vault")
```

<figure><img src="https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FbnXBxfI3vmnnmjdy2raX%2Fimage.png?alt=media&#x26;token=3079642c-34d9-453a-9054-0b688cd52986" alt=""><figcaption></figcaption></figure>

If you do the above, and run your integration, you should see this in your run history

<figure><img src="https://688288018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1flQ2To8tQpCQWl2Ty9U%2Fuploads%2FpS6IXsPSf1r0R5dlrlRq%2FScreenshot%202025-04-02%20at%2011.44.02%E2%80%AFAM.png?alt=media&#x26;token=7a36b338-58e9-450c-bb6b-22a6c7ff95d1" alt=""><figcaption></figcaption></figure>

If you want your vault contents to be accessible throughout the rest of your integration (meaning, not just within the before\_hook), you can `keep` my\_data:

```python
with open_vault('my-vault') as vault:
    my_data = vault.get("my-item")
debug(my_data, label="Here's what was in the vault")
keep(my_data = my_data) # my_data can now be accessed in any other hook or expression
```
