# Running a Data Agent database workflow

## Getting the parameter names for the workflow

When you run a workflow, you must provide any parameter values that the workflow requires.

On the workflow details panel, to get the parameter names, hover over each field label.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FuyAiZ9AvnGnkxQEw2l1E%2FDataAgent_WorkflowParameterTooltip.png?alt=media&#x26;token=b797f464-490f-4ac4-a5c7-d58bdf243095" alt=""><figcaption><p>Tooltip with the workflow parameter name</p></figcaption></figure>

The script view also lists the parameters.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FD8q15I0x93dhvcJQxU9b%2FDataAgent_WorkflowParameterScript.png?alt=media&#x26;token=f76e7478-3337-443a-8f69-7213d0cf1d1a" alt=""><figcaption><p>Parameters list on script view for a workflow</p></figcaption></figure>

## Making the run request

From the npm package, to run a workflow:

```
import { runWorkflow } from '@fabricate-tools/client'


const { result, task } = await runWorkflow({
  apiKey: 'your-api-key',
  apiUrl: 'https://fabricate.tonic.ai/api/v1',
  workspace: 'my_workspace',
  database: 'my_database',
  workflow: 'my_workflow',
  params: {
    paramName: 'paramValue'
  }
})
```

You can optionally request progress updates:

```
const { result, task } = await runWorkflow({
  apiKey: 'your-api-key',
  apiUrl: 'https://fabricate.tonic.ai/api/v1',
  workspace: 'my_workspace',
  database: 'my_database',
  workflow: 'my_workflow',
  params: {
    paramName: 'paramValue'
  },
  onProgress: ({ status, message }) => {
    console.log(`[${status}] ${message}`)
  },
})
```

## Listing and downloading workflow generated files

### **Listing the generated files**

To run the workflow and then list the files that the workflow generates:

```
const { result, task, downloadFile, downloadAllFiles } = await runWorkflow({
  apiKey: 'your-api-key',
  apiUrl: 'https://fabricate.tonic.ai/api/v1',
  workspace: 'my_workflow',
  database: 'my_database',
  workflow: 'export_report',
  params: { format: 'csv' },
})

if (task.files && task.files.length > 0) {
  console.log('Generated files:')
  for (const file of task.files) {
    console.log(`  - ${file.name} (${file.content_type}, ${file.size} bytes)`)
  }
}
```

### **Downloading all of the generated files**

To run a workflow and then download all of the generated files:

```
const { result, task, downloadFile, downloadAllFiles } = await runWorkflow({
  apiKey: 'your-api-key',
  apiUrl: 'https://fabricate.tonic.ai/api/v1',
  workspace: 'my_workflow',
  database: 'my_database',
  workflow: 'export_report',
  params: { format: 'csv' },
})

  await downloadAllFiles('./output')
}
```

### **Downloading a specific file**

To run a workflow and then download a specific generated file based on its identifier to a specified file name:

```
const { result, task, downloadFile, downloadAllFiles } = await runWorkflow({
  apiKey: 'your-api-key',
  apiUrl: 'https://fabricate.tonic.ai/api/v1',
  workspace: 'my_workflow',
  database: 'my_database',
  workflow: 'export_report',
  params: { format: 'csv' },
})


  const file = task.files[0]
  await downloadFile(file.id, `./output/${file.name}`)
}
```
