---
title: "API Example - Metadata Export"
canonical: "https://docs.vaultspeed.com/space/VPD/3164700800/API%20Example%20-%20Metadata%20Export"
format: markdown
---
This page has a small example of using the VaultSpeed API to create and get a metadata export CSV file.

For easy testing and readability, the screenshots were taken from Postman.

 

> Macro (toc)

## Get Access Token

The first step is to get your access token which you can use in the rest of the API calls to identify to the application.

with a POST request to the login endpoint, you can get your access token:

| **Type** | POST |
| --- | --- |
| **URL** | [https://app.vaultspeed.com/api/login](https://app.vaultspeed.com/api/login) |
| **Authorization** | / |
| **Body** | ```
{
  "username": "myUser@company",
  "password": "MySecret"
}
``` |
| **Response** | ```
{
    "access_token": "ABC.......UA"
}
``` |

![image](media://da72f551-dd3f-4882-8b96-e042ffc18fa3)

## Create Metadata Export Preset

With your access token as an authentication credential (bearer token), you can now create a new metadata-export preset using the metadata-export/preset endpoint

| **Type** | POST |
| --- | --- |
| **URL** | [https://app.vaultspeed.com/api/metadata-export/preset](https://app.vaultspeed.com/api/metadata-export/preset) |
| **Authorization** | Access Token from Step 1 |
| **Body** | ```
{
  "name": "source to dv table lineage",
  "description": "source table names with their related Data Vault table names",
  "file_name": "src_dv_lineage",
  "properties": [
    "src_physical_schema",
    "src_table_name",
    "dv_physical_schema",
    "dv_table_name"
  ]
}
``` |
| **Response** | ```
{
    "preset_id": 4
}
``` |

![image](media://2ffda872-aab6-4fc2-ba9c-929ef6264d4d)

## Get all Correct IDs

For a metadata export task to be created, we need both the metadata preset ID (which we just got from the above creation command) and the Business Vault ID, related to the Data Vault where we want to perform our metadata export.

For this, we will call the business-vaults endpoint, but we will immediately filter based on the name of the business Vault release we are looking for. We just named our Business Vault **“init”**.

| **Type** | GET |
| --- | --- |
| **URL** | `https://app.vaultspeed.com/api/data-vaults/{dv-id}/business-vaults/releases?filter[where][bv_vs_name]=init` |
| **Authorization** | Access Token from Step 1 |
| **Body** | / |
| **Response** | ```
[
    {
        "bv_vs_id": 1,
        "bv_vs_name": "init",
        "bv_vs_number": 1,
        "bv_vs_comment": "initial release",
        "bv_vs_date": "2023-05-12T08:24:57Z",
        "bv_locked": true,
        "dv_id": 1,
        "dv_vs_id": 1
    }
]
``` |

Based on the response we see that the internal id = 20.

> 📝 **Note:** The endpoint for retrieving Business Vault releases was updated with the release of RBAC. Ensure you are using the correct Data Vault ID in the API URL.

![Screenshot 2024-08-30 at 11.58.00.png](media://63927728-3a11-4c24-9186-21076307fc4f)


## Create Metadata Export Task

With this information, we can now call the endpoint to create a metadata export task, for the Business Vault we just got the ID from, for the export preset ID we created earlier.

When we get a task_id back, we know the task is created and will be picked up by the VaultSpeed engine shortly

| **Type** | POST |
| --- | --- |
| **URL** | [https://app.vaultspeed.com/api/metadata-export/export](https://app.vaultspeed.com/api/metadata-export/export) |
| **Authorization** | Access Token from Step 1 |
| **Body** | ```
{
  "bv_vs_id": 20,
  "lineage_preset_id": 4
}
``` |
| **Response** | ```
{
    "task_set_id": 123
}
``` |

![image](media://396fdd2b-7034-427a-8768-14ab1c24d075)

## Check if the Export is Available

Now we can check if the task is already picked up and carried out by VaultSpeed. To do this we can call the check endpoint.

| **Type** | GET |
| --- | --- |
| **URL** | [https://app.vaultspeed.com/api/metadata-export/check](https://app.vaultspeed.com/api/metadata-export/check) |
| **Authorization** | Access Token from Step 1 |
| **Body** | / |
| **Response** | ```
{
    "ready": true,
    "message": "Export of lineage metadata with preset source to dv table lineage for bv release R4 of Data Vault MATILLION_DEMO is ready for download.",
    "file_name": "SRC_DV_LINEAGE",
    "preset_name": "source to dv table lineage"
}
``` |

![image](media://ce139554-cb0c-4e83-b7b5-c8533d6661ed)

## Download the CSV File

When our task is ready and the file can be downloaded, we can do so by calling the download endpoint.

| **Type** | GET |
| --- | --- |
| **URL** | [https://app.vaultspeed.com/api/metadata-export/download](https://app.vaultspeed.com/api/metadata-export/download) |
| **Authorization** | Access Token from Step 1 |
| **Body** | / |
| **Response** | ```
src_physical_schema;dv_physical_schema;src_table_name;dv_table_name
SPEEDSHOP_SALES;MATILLION_DEMO_FL;INVOICES;LNK_INVOICES_CUSTOMERS
SPEEDSHOP_SALES;MATILLION_DEMO_FL;CUST_PURCHASED_EBICYCLE;LND_PURCHASED_PRODUCTS
SPEEDSHOP_PRODUCTS;MATILLION_DEMO_FL;NON_MOTOR_VEHICLES;SAT_PRODUCTS_NONMOTORVEHICLES_PRODUCTS
SPEEDSHOP_SALES;MATILLION_DEMO_FL;CUST_PURCHASED_BICYCLE;LND_PURCHASED_PRODUCTS
SPEEDSHOP_SALES;MATILLION_DEMO_FL;BICYCLES;SAT_SLS_BICYCLES_PRODUCTS
SPEEDSHOP_SALES;MATILLION_DEMO_FL;BICYCLES;HUB_PRODUCTS
...
...
``` |

![image](media://c2140f91-3926-4919-8cc1-26c414b1017e)