# Generating data from the API

## Sending the generation request <a href="#api-generation-request" id="api-generation-request"></a>

To generate data for an existing database:

```
POST /api/v1/generate_tasks
```

This method expects a JSON object as the request body with the following parameters:

{% code overflow="wrap" %}

```json
{
  "workspace": string,
  "database": string,
  "format": string,
  "connection": string,
  "entity": string,
  "overrides": object
}
```

{% endcode %}

Where:

<table data-header-hidden><thead><tr><th width="233.265625" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top"><code>workspace</code></td><td valign="top">The name of the workspace in which the database resides.</td></tr><tr><td valign="top"><code>database</code></td><td valign="top">The name of the database for which to generate data.</td></tr><tr><td valign="top"><code>format</code></td><td valign="top">(Optional) The format of the generated data.<br><br>Allows values are <code>"sql"</code>, <code>"sqlite",</code> <code>"postgres-optimized"</code>, <code>"csv"</code>, or <code>"jsonl"</code>.</td></tr><tr><td valign="top"><code>connection</code></td><td valign="top">(Optional) The name of the target database connection to insert the generated data into.<br><br>If you provide a format, then do not provide a connection.<br><br>When you provide a connection, the target database and all of the tables must already exist.</td></tr><tr><td valign="top"><code>entity</code></td><td valign="top">(Optional) The name of a table to generate.<br><br>When provided, Fabricate only generates data for that table, and the generated data is provided as plain text instead of a .zip file.</td></tr><tr><td valign="top"><code>overrides</code></td><td valign="top">(Optional) Overrides to variable values and table column configuration.<br><br>Only available for rule-based databases. Cannot use for Data Agent databases.<br><br>For more information, go to <a data-mention href="#generation-request-overrides">#generation-request-overrides</a>. </td></tr></tbody></table>

## Get the status of a data generation task <a href="#generation-get-status" id="generation-get-status"></a>

To check the status of a data generation task:

```
GET /api/v1/generate_tasks/:id
```

Where:

<table data-header-hidden><thead><tr><th width="124.078125" valign="top">Name</th><th valign="top">Description</th></tr></thead><tbody><tr><td valign="top"><code>id</code></td><td valign="top">The UUID of the data generation task to get</td></tr></tbody></table>

The response is a JSON object in the same format as the response from the `POST /api/v1/generate_tasks` endpoint.

## Loading the generated data into your database <a href="#generation-load-data" id="generation-load-data"></a>

The `download_url` field in the response from `GET /api/v1/generate_tasks/:id` contains a URL to download the generated data.

Depending on the format of the data, to load it into your database, use the appropriate method:

#### PostgreSQL <a href="#postgres" id="postgres"></a>

The data is provided as a zip file.

To load the data into your database, unzip it and then run the following command:

```
psql -U <username> -d <database> -f path/to/dir/load.sql
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tonic.ai/fabricate/fabricate-api/using-the-fabricate-api/api-generate-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
