> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usedatabrain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Datamart

> Delete a datamart from your organization. This action cannot be undone.

Permanently delete a datamart from your organization. This will remove the datamart and all its associated configurations.

<Warning>
  **Endpoint Migration Notice:** We're transitioning to kebab-case endpoints. The new endpoint is `/api/v2/data-app/datamart`. The old endpoint `/api/v2/dataApp/datamart` will be deprecated soon. Please update your integrations to use the new endpoint format.
</Warning>

<Danger>
  This action is irreversible. Once a datamart is deleted, all its data configurations and associated embed configurations will be permanently removed.
</Danger>

## Endpoint Formats

<Tabs>
  <Tab title="New Endpoint (Recommended)">
    ```
    DELETE https://api.usedatabrain.com/api/v2/data-app/datamart?datamartName={name}
    ```

    **Use this endpoint** for all new integrations. Uses REST-ful DELETE method with query parameters.
  </Tab>

  <Tab title="Legacy Endpoint (Deprecated Soon)">
    ```
    POST https://api.usedatabrain.com/api/v2/dataApp/datamart/delete
    Content-Type: application/json

    {
      "datamartName": "sales-analytics"
    }
    ```

    This endpoint still works but will be deprecated. Uses POST method with JSON body.
  </Tab>
</Tabs>

## Authentication

This endpoint requires a service token in the Authorization header. Service tokens differ from data app API keys and provide organization-level permissions.

To access your service token:

1. In **Settings** page, navigate to the **Service Tokens** section.
2. Click the **"Generate Token"** button to create a new service token if you don't have one already.

Use this token as the Bearer value in your Authorization header.

<Panel>
  <RequestExample>
    ```bash Authentication theme={"dark"}
    curl --request DELETE \
      --url 'https://api.usedatabrain.com/api/v2/data-app/datamart?datamartName=sales-analytics' \
      --header 'Authorization: Bearer dbn_live_abc123...'
    ```
  </RequestExample>
</Panel>

## Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for API authentication. Use your service token.

  ```
  Authorization: Bearer dbn_live_abc123...
  ```
</ParamField>

## Query Parameters

<ParamField query="datamartName" type="string" required>
  The name of the datamart to delete. Must match an existing datamart name in your organization.

  <Expandable title="Finding datamart names">
    * Use the List Datamarts API to get all datamart names
    * Check the response from datamart creation
    * Available in the DataBrain dashboard when viewing datamarts
  </Expandable>
</ParamField>

## Response

<ResponseField name="id" type="string">
  The name of the deleted datamart for confirmation.
</ResponseField>

<ResponseField name="error" type="null">
  Error field, null when successful.
</ResponseField>

## Examples

<Panel>
  <RequestExample>
    ```bash cURL theme={"dark"}
    curl --request DELETE \
      --url 'https://api.usedatabrain.com/api/v2/data-app/datamart?datamartName=sales-analytics' \
      --header 'Authorization: Bearer dbn_live_abc123...'
    ```

    ```javascript Node.js icon="fa-brands fa-node-js" theme={"dark"}
    const datamartName = 'sales-analytics';
    const response = await fetch(`https://api.usedatabrain.com/api/v2/data-app/datamart?datamartName=${encodeURIComponent(datamartName)}`, {
      method: 'DELETE',
      headers: {
        'Authorization': 'Bearer dbn_live_abc123...'
      }
    });

    const data = await response.json();
    console.log('Deleted datamart:', data.id);
    ```

    ```python Python icon="fa-brands fa-python" theme={"dark"}
    import requests

    url = "https://api.usedatabrain.com/api/v2/data-app/datamart"
    headers = {
        "Authorization": "Bearer dbn_live_abc123..."
    }
    params = {
        "datamartName": "sales-analytics"
    }

    response = requests.delete(url, headers=headers, params=params)
    data = response.json()
    print(f"Deleted datamart: {data['id']}")
    ```

    ```ruby Ruby icon="fa-solid fa-gem" theme={"dark"}
    require 'net/http'
    require 'json'

    uri = URI('https://api.usedatabrain.com/api/v2/data-app/datamart')
    params = { datamartName: 'sales-analytics' }
    uri.query = URI.encode_www_form(params)

    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true

    request = Net::HTTP::Delete.new(uri)
    request['Authorization'] = 'Bearer dbn_live_abc123...'

    response = http.request(request)
    data = JSON.parse(response.body)
    puts "Deleted datamart: #{data['id']}"
    ```

    ```java Java icon="fa-brands fa-java" theme={"dark"}
    import java.net.http.HttpClient;
    import java.net.http.HttpRequest;
    import java.net.http.HttpResponse;
    import java.net.URI;
    import java.net.URLEncoder;
    import java.nio.charset.StandardCharsets;

    public class DataBrainDeleteDatamartAPI {
        public static void main(String[] args) throws Exception {
            HttpClient client = HttpClient.newHttpClient();
            
            String datamartName = URLEncoder.encode("sales-analytics", StandardCharsets.UTF_8);
            String url = String.format(
                "https://api.usedatabrain.com/api/v2/data-app/datamart?datamartName=%s",
                datamartName
            );
            
            HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer dbn_live_abc123...")
                .DELETE()
                .build();
                
            HttpResponse<String> response = client.send(request, 
                HttpResponse.BodyHandlers.ofString());
                
            System.out.println("Response: " + response.body());
        }
    }
    ```

    ```go Go icon="fa-brands fa-golang" theme={"dark"}
    package main

    import (
        "encoding/json"
        "fmt"
        "net/http"
        "net/url"
    )

    type DeleteDatamartResponse struct {
        Id    string      `json:"id"`
        Error interface{} `json:"error"`
    }

    func main() {
        baseURL := "https://api.usedatabrain.com/api/v2/data-app/datamart"
        params := url.Values{}
        params.Add("datamartName", "sales-analytics")
        
        fullURL := fmt.Sprintf("%s?%s", baseURL, params.Encode())
        
        req, _ := http.NewRequest("DELETE", fullURL, nil)
        req.Header.Set("Authorization", "Bearer dbn_live_abc123...")
        
        client := &http.Client{}
        resp, err := client.Do(req)
        if err != nil {
            panic(err)
        }
        defer resp.Body.Close()
        
        var datamartResp DeleteDatamartResponse
        json.NewDecoder(resp.Body).Decode(&datamartResp)
        
        fmt.Printf("Deleted datamart: %s\n", datamartResp.Id)
    }
    ```

    ```php PHP icon="fa-brands fa-php" theme={"dark"}
    <?php
    $params = http_build_query([
        'datamartName' => 'sales-analytics'
    ]);

    $url = 'https://api.usedatabrain.com/api/v2/data-app/datamart?' . $params;

    $options = [
        'http' => [
            'header' => 'Authorization: Bearer dbn_live_abc123...',
            'method' => 'DELETE'
        ]
    ];

    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $response = json_decode($result, true);

    echo "Deleted datamart: " . $response['id'];
    ?>
    ```
  </RequestExample>

  <ResponseExample>
    ```json Success Response theme={"dark"}
    {
      "id": "sales-analytics",
      "error": null
    }
    ```

    ```json Error Response (400) theme={"dark"}
    {
      "error": {
        "code": "INVALID_REQUEST_BODY",
        "message": "Datamart not found",
        "status": 400
      }
    }
    ```
  </ResponseExample>
</Panel>

## Legacy Endpoint Examples

<Note>
  The following examples use the deprecated POST endpoint. These are provided for reference only. **Please use the DELETE endpoint examples above for all new integrations.**
</Note>

<Panel>
  <RequestExample>
    ```bash cURL theme={"dark"}
    curl --request POST \
      --url 'https://api.usedatabrain.com/api/v2/dataApp/datamart/delete' \
      --header 'Authorization: Bearer dbn_live_abc123...' \
      --header 'Content-Type: application/json' \
      --data '{
        "datamartName": "sales-analytics"
      }'
    ```

    ```javascript Node.js icon="fa-brands fa-node-js" theme={"dark"}
    const response = await fetch('https://api.usedatabrain.com/api/v2/dataApp/datamart/delete', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer dbn_live_abc123...',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        datamartName: 'sales-analytics'
      })
    });

    const data = await response.json();
    console.log('Deleted datamart:', data.id);
    ```

    ```python Python icon="fa-brands fa-python" theme={"dark"}
    import requests

    url = "https://api.usedatabrain.com/api/v2/dataApp/datamart/delete"
    headers = {
        "Authorization": "Bearer dbn_live_abc123...",
        "Content-Type": "application/json"
    }
    data = {
        "datamartName": "sales-analytics"
    }

    response = requests.post(url, headers=headers, json=data)
    result = response.json()
    print(f"Deleted datamart: {result['id']}")
    ```

    ```ruby Ruby icon="fa-solid fa-gem" theme={"dark"}
    require 'net/http'
    require 'json'

    uri = URI('https://api.usedatabrain.com/api/v2/dataApp/datamart/delete')
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true

    request = Net::HTTP::Post.new(uri)
    request['Authorization'] = 'Bearer dbn_live_abc123...'
    request['Content-Type'] = 'application/json'
    request.body = {
      datamartName: 'sales-analytics'
    }.to_json

    response = http.request(request)
    data = JSON.parse(response.body)
    puts "Deleted datamart: #{data['id']}"
    ```

    ```java Java icon="fa-brands fa-java" theme={"dark"}
    import java.net.http.HttpClient;
    import java.net.http.HttpRequest;
    import java.net.http.HttpResponse;
    import java.net.URI;

    public class DataBrainDeleteDatamartAPI {
        public static void main(String[] args) throws Exception {
            HttpClient client = HttpClient.newHttpClient();
            
            String requestBody = """
                {
                    "datamartName": "sales-analytics"
                }""";
            
            HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.usedatabrain.com/api/v2/dataApp/datamart/delete"))
                .header("Authorization", "Bearer dbn_live_abc123...")
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(requestBody))
                .build();
                
            HttpResponse<String> response = client.send(request, 
                HttpResponse.BodyHandlers.ofString());
                
            System.out.println("Response: " + response.body());
        }
    }
    ```

    ```go Go icon="fa-brands fa-golang" theme={"dark"}
    package main

    import (
        "bytes"
        "encoding/json"
        "fmt"
        "net/http"
    )

    type DeleteDatamartRequest struct {
        DatamartName string `json:"datamartName"`
    }

    type DeleteDatamartResponse struct {
        Id    string      `json:"id"`
        Error interface{} `json:"error"`
    }

    func main() {
        reqData := DeleteDatamartRequest{
            DatamartName: "sales-analytics",
        }
        
        jsonData, _ := json.Marshal(reqData)
        
        req, _ := http.NewRequest("POST", "https://api.usedatabrain.com/api/v2/dataApp/datamart/delete", bytes.NewBuffer(jsonData))
        req.Header.Set("Authorization", "Bearer dbn_live_abc123...")
        req.Header.Set("Content-Type", "application/json")
        
        client := &http.Client{}
        resp, err := client.Do(req)
        if err != nil {
            panic(err)
        }
        defer resp.Body.Close()
        
        var datamartResp DeleteDatamartResponse
        json.NewDecoder(resp.Body).Decode(&datamartResp)
        
        fmt.Printf("Deleted datamart: %s\n", datamartResp.Id)
    }
    ```

    ```php PHP icon="fa-brands fa-php" theme={"dark"}
    <?php
    $url = 'https://api.usedatabrain.com/api/v2/dataApp/datamart/delete';
    $data = [
        'datamartName' => 'sales-analytics'
    ];

    $options = [
        'http' => [
            'header' => [
                'Authorization: Bearer dbn_live_abc123...',
                'Content-Type: application/json'
            ],
            'method' => 'POST',
            'content' => json_encode($data)
        ]
    ];

    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $response = json_decode($result, true);

    echo "Deleted datamart: " . $response['id'];
    ?>
    ```
  </RequestExample>

  <ResponseExample>
    ```json Success Response theme={"dark"}
    {
      "id": "sales-analytics",
      "error": null
    }
    ```

    ```json Error Response (400) theme={"dark"}
    {
      "error": {
        "code": "INVALID_REQUEST_BODY",
        "message": "Datamart not found",
        "status": 400
      }
    }
    ```
  </ResponseExample>
</Panel>

## Error Codes

<ResponseField name="INVALID_REQUEST_BODY" type="string">
  **Invalid request body** - Check that datamartName is provided and valid
</ResponseField>

<ResponseField name="INTERNAL_SERVER_ERROR" type="string">
  **Unexpected failure** - Internal server error occurred
</ResponseField>

## HTTP Status Code Summary

| Status Code | Description                                                        |
| ----------- | ------------------------------------------------------------------ |
| 200         | **OK** - Datamart deleted successfully                             |
| 400         | **Bad Request** - Invalid request parameters or datamart not found |
| 401         | **Unauthorized** - Invalid or expired API token                    |
| 500         | **Internal Server Error** - Unexpected server error                |

## Possible Errors

| Code                    | Message            | HTTP Status |
| ----------------------- | ------------------ | ----------- |
| INVALID\_REQUEST\_BODY  | Datamart not found | 400         |
| INTERNAL\_SERVER\_ERROR | Unexpected failure | 500         |

## Best Practices

<CardGroup cols={2}>
  <Card title="Check Dependencies" icon="link">
    Before deleting, verify no embed configurations depend on this datamart
  </Card>

  <Card title="Backup Data" icon="database">
    Consider exporting important configurations before deletion
  </Card>
</CardGroup>

<CardGroup cols={2}>
  <Card title="Test Environment" icon="flask">
    Test deletion process in a non-production environment first
  </Card>

  <Card title="Documentation" icon="book">
    Document the deletion for audit and compliance purposes
  </Card>
</CardGroup>

## Quick Start Guide

<Steps>
  <Step title="List your datamarts">
    First, see which datamarts you have available to identify the one to delete:

    ```bash theme={"dark"}
    curl --request GET \
      --url https://api.usedatabrain.com/api/v2/data-app/datamarts \
      --header 'Authorization: Bearer dbn_live_abc123...'
    ```
  </Step>

  <Step title="Check dependencies">
    Before deleting, ensure no embed configurations are using this datamart. Use the List Embeds API to verify.
  </Step>

  <Step title="Delete the datamart">
    Make the deletion request with the exact datamart name as a query parameter:

    ```bash theme={"dark"}
    curl --request DELETE \
      --url 'https://api.usedatabrain.com/api/v2/data-app/datamart?datamartName=sales-analytics' \
      --header 'Authorization: Bearer dbn_live_abc123...'
    ```
  </Step>

  <Step title="Update dependent configurations">
    Update any embed configurations that were using this datamart to reference a different datamart:

    ```javascript theme={"dark"}
    // Update embeds that used the deleted datamart
    await updateEmbed({
      embedId: 'embed_123',
      accessSettings: {
        datamartName: 'replacement-datamart'
      }
    });
    ```
  </Step>
</Steps>

<Warning>
  **Critical:** This action permanently deletes the datamart and cannot be undone. Ensure all dependent configurations are updated before deletion.
</Warning>

## Next Steps

<CardGroup cols={2}>
  <Card title="Create Datamart" href="/developer-docs/helpers/api-reference/create-datamart">
    Create a new datamart to replace the deleted one
  </Card>

  <Card title="List Datamarts" href="/developer-docs/helpers/api-reference/list-datamarts">
    View all remaining datamarts in your organization
  </Card>
</CardGroup>

<CardGroup cols={2}>
  <Card title="Embed a Pre-built Dashboard/Metric" href="/developer-docs/helpers/api-reference/create-embed">
    Create new embed configurations for your remaining datamarts
  </Card>

  <Card title="Guest Token API" href="/developer-docs/helpers/api-reference/token">
    Generate tokens for your updated configurations
  </Card>
</CardGroup>
