# Managing databases from the API

## Getting database information

### Getting all of the databases in a workspace

To list all of the databases in a specific workspace:

```
GET /api/v1/workspaces/:workspace_name/databases
```

The response contains an array of database objects. For each database, the database object contains the following fields:

{% code overflow="wrap" %}

```json
[
  {
    "id": "c50db909-6617-40d8-8c81-47de1b2e9806",
    "name": "CREATED_FROM_API",
    "created_at": "2025-03-20T08:44:41Z",
    "updated_at": "2025-03-20T08:44:42Z",
    "last_generated": "2025-03-20T08:44:42Z",
    "data_url": "http://fabricate.tonic.ai/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6IjFjMTg5MjNmLWZkZDAtNDRhZC04Y2U5LTE3Mjk5ZTBkNDEyNCIsInB1ciI6ImJsb2JfaWQifX0=--c9d77fa2a060bfd8c90813f960a901d7ea75c7c1/CREATED_FROM_API.zip",
    "workspace": {
      "id": "7edef645-87a5-46ef-9ea1-cce33cd9a543",
      "name": "Fabricate"
    },
  }
]
```

{% endcode %}

Where:

<table data-header-hidden><thead><tr><th width="175.2890625" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top"><code>id</code></td><td valign="top">The UUID of the database.</td></tr><tr><td valign="top"><code>name</code></td><td valign="top">The name of the database.</td></tr><tr><td valign="top"><code>created_at</code></td><td valign="top">The date and time when the database was created.</td></tr><tr><td valign="top"><code>updated_at</code></td><td valign="top">The date and time the database configuration was most recently updated.</td></tr><tr><td valign="top"><code>last_generated</code></td><td valign="top">The date and time that the database data was most recently generated.</td></tr><tr><td valign="top"><code>data_url</code></td><td valign="top">The URL to download the most recently generated data.<br><br>Until the data is generated, this is null.</td></tr><tr><td valign="top"><code>workspace</code></td><td valign="top">The identifier and name of the workspace that the database belongs to.</td></tr></tbody></table>

For an example, go to [list-databases.js](https://github.com/mockaroo/fabricate-api-examples/blob/main/js/list-databases.js) in the `fabricate-api-examples` GitHub repository.

### Getting details for a specific database

To get the details for a specific database by name:

```
GET /api/v1/workspaces/:workspace_name/databases/:database_name
```

The response is a database object with the full details about the database configuration. For information about the database object, go to [#database-attributes](https://docs.tonic.ai/fabricate/fabricate-api-and-cli/data-model#database-attributes "mention").

For an example, go to [get-database.js](https://github.com/mockaroo/fabricate-api-examples/blob/main/js/get-database.js) in the `fabricate-api-examples` GitHub repository.

## Creating and managing database configuration

### Creating or updating a database

To create a database or update an existing database:

```
POST /api/v1/workspaces/:workspace_name/databases
```

The request body is a database object with the database configuration.

The response contains a database object with the new or updated database configuration.

&#x20;For information about the database object, go to [#database-attributes](https://docs.tonic.ai/fabricate/fabricate-api-and-cli/data-model#database-attributes "mention").

For an example, go to [upsert-database.js](https://github.com/mockaroo/fabricate-api-examples/blob/main/js/upsert-database.js) in the `fabricate-api-examples` GitHub repository.

### Deleting a database <a href="#delete-a-database" id="delete-a-database"></a>

To delete a database:

```
DELETE /api/v1/workspaces/:workspace_name/databases/:database_name
```

Returns an empty response body with a 200 status code.

For an example, go to [delete-database.js](https://github.com/mockaroo/fabricate-api-examples/blob/main/js/delete-database.js) in the `fabricate-api-examples` GitHub repository.

## Adding static data to a table

In Fabricate, instead of generating the data for a table, you can provide static data in the form of a .csv file. For more information, go to [table-static-data](https://docs.tonic.ai/fabricate/rule-based-tables-and-columns/database-tables/table-static-data "mention").

From the API, to update the .csv file content:

{% code overflow="wrap" %}

```
POST /api/v1/workspaces/:workspace_name/databases/:database_name/entities/:table_name/source
```

{% endcode %}

This method expects a multipart/form-data request body with a `file` parameter that contains the contents of the .csv file to use for the table data.

The response contains an empty response body with a 200 code.

For an example, go to [update-source-data.js](https://github.com/mockaroo/fabricate-api-examples/blob/main/js/update-source-data.js) in the `fabricate-api-examples` GitHub repository.
