> For the complete documentation index, see [llms.txt](https://support.attackforge.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.attackforge.com/app/automations-and-integrations/self-service-restful-api/exporting-to-csv.md). Agents can also search and read this documentation through its [MCP server](https://support.attackforge.com/~gitbook/mcp).

# EXPORTING TO CSV

## Overview

Export AttackForge data to a CSV file, so you can analyse it in a spreadsheet, build your own reports or import it into other tools. You fetch the data with the [Self-Service RESTful API](https://support.attackforge.com/app/automations-and-integrations/self-service-restful-api), then convert it to CSV with [jq](https://jqlang.org/), a free command-line JSON processor.

This page uses the **getVulnerabilities** API method, but the same approach works for any Self-Service API method.

<figure><img src="https://372186556-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8s1QY2Q6YTHB4a6DMu%2Fuploads%2F3STFZ6CDvZXMkbN0ZLrg%2Fexporting-to-csv-at-a-glance.svg?alt=media&amp;token=f6edac09-c91e-4c35-b5a1-558e53d5a288" alt=""><figcaption></figcaption></figure>

## Why it matters

| Benefit                 | What it means                                                                    |
| ----------------------- | -------------------------------------------------------------------------------- |
| **Choose your columns** | Export only the fields you need, in the order you want                           |
| **Filter first**        | Export only the vulnerabilities that match a filter, such as Open                |
| **Repeatable**          | Run the same command whenever you need a fresh export, or schedule it            |
| **Works anywhere**      | jq is free, runs on Linux, macOS and Windows, and has no dependencies            |
| **Feeds other tools**   | Open the CSV in Excel or Google Sheets, or import it into BI and ticketing tools |

## Who uses it

| Role                                     | Typical use                                              |
| ---------------------------------------- | -------------------------------------------------------- |
| **Security and project managers**        | Export open or closed vulnerabilities for status reports |
| **Analysts**                             | Pull data into spreadsheets and BI tools                 |
| **Remediation teams**                    | Import vulnerabilities into their own trackers           |
| **Developers and integration engineers** | Script regular exports                                   |

## Other ways to get data out

* [**AI MCP**](https://support.attackforge.com/app/automations-and-integrations/ai-mcp-and-skills)**:** ask an AI assistant to build a spreadsheet or table from your vulnerabilities, without writing jq.
* [**Report automation**](https://support.attackforge.com/app/automations-and-integrations/report-automation)**:** generate formatted reports automatically.
* [**Flows**](https://support.attackforge.com/app/automations-and-integrations/flows)**:** send data to another system when something changes in AttackForge.

## Before you start

You need:

* access to the **getVulnerabilities** API method. See [Give users access to API methods](https://support.attackforge.com/app/automations-and-integrations/self-service-restful-api).
* your API key, from **Profile > Secrets**
* your AttackForge hostname, such as `demo.attackforge.com`
* jq and cURL

## Install jq on Linux

Run:

```
sudo apt-get install jq
```

For other ways to install jq, see [Download jq](https://jqlang.org/download/).

## Install jq on Windows

Run:

```
winget install jqlang.jq
```

For other ways to install jq, see [Download jq](https://jqlang.org/download/).

### Choose where to run the commands

The commands on this page are written for **Windows Command Prompt**:

* **Linux and macOS (bash or zsh):** they also work, except for the filter commands. Put a backslash before `$eq`, writing `\$eq`, so the shell doesn't treat it as a variable.
* **PowerShell:** use `curl.exe` instead of `curl`, because `curl` can run a different PowerShell command.

## Export vulnerabilities to CSV

1. Open a command window or terminal.
2. Run this command. Replace `<YOUR-TENANT>` with your AttackForge hostname and `<YOUR-API-KEY>` with your API key.

```
curl -X GET "https://<YOUR-TENANT>/api/ss/vulnerabilities" -H "Host: <YOUR-TENANT>" -H "X-SSAPI-KEY: <YOUR-API-KEY>" -H "Content-Type: application/json" -H "Connection: close" | jq -r "(.vulnerabilities[] | [.vulnerability_id, .vulnerability_title, .vulnerability_created, .vulnerability_priority, .vulnerability_status, .vulnerability_status_updated, .vulnerability_affected_asset_name, if(try(.vulnerability_affected_assets)) then [.vulnerability_affected_assets[].asset.name] | join(\", \") else \"\" end, .vulnerability_retest, .vulnerability_project_name, .vulnerability_description, .vulnerability_attack_scenario, .vulnerability_remediation_recommendation, .vulnerability_steps_to_reproduce]) | @csv" > filtered_vulns.csv
```

This creates `filtered_vulns.csv` in the current folder, with one row for each vulnerability you can access.

### What the command does

| Part                                                         | What it does                                                             |
| ------------------------------------------------------------ | ------------------------------------------------------------------------ |
| `curl -X GET "https://<YOUR-TENANT>/api/ss/vulnerabilities"` | Calls the getVulnerabilities API method                                  |
| `-H "X-SSAPI-KEY: <YOUR-API-KEY>"`                           | Sends your API key                                                       |
| `\| jq -r "…"`                                               | Passes the response to jq, which outputs raw text                        |
| `.vulnerabilities[] \| [ … ]`                                | Makes one row for each vulnerability, from the fields in the brackets    |
| `if(try(.vulnerability_affected_assets)) then … end`         | Joins the names of grouped assets with a comma, or leaves the cell empty |
| `@csv`                                                       | Formats each row as CSV                                                  |
| `> filtered_vulns.csv`                                       | Saves the output to a file                                               |

### The columns

| Column                     | Field                                         | Example                                        |
| -------------------------- | --------------------------------------------- | ---------------------------------------------- |
| Id                         | `.vulnerability_id`                           |                                                |
| Title                      | `.vulnerability_title`                        | Blind SQL Injection                            |
| Created                    | `.vulnerability_created`                      | A date and time                                |
| Priority                   | `.vulnerability_priority`                     | Critical, High, Medium, Low or Info            |
| Status                     | `.vulnerability_status`                       | Open or Closed                                 |
| Status Updated             | `.vulnerability_status_updated`               | A date and time                                |
| Affected Asset Name        | `.vulnerability_affected_asset_name`          | attackforge.com                                |
| Affected Assets            | `.vulnerability_affected_assets[].asset.name` | Each asset's name, when you use grouped assets |
| Retest                     | `.vulnerability_retest`                       | Yes or No                                      |
| Project Name               | `.vulnerability_project_name`                 | Web App Pentest                                |
| Description                | `.vulnerability_description`                  |                                                |
| Attack Scenario            | `.vulnerability_attack_scenario`              |                                                |
| Remediation Recommendation | `.vulnerability_remediation_recommendation`   |                                                |
| Steps to Reproduce         | `.vulnerability_steps_to_reproduce`           |                                                |

### Change or reorder the columns

Edit the list of fields inside the square brackets, after `.vulnerabilities[] |`. Change the order to change the column order, or remove fields you don't need.

### Add more fields

You can add any field the API returns. For the fields, see [getVulnerabilities](https://docs.attackforge.com/rest-api/pages/getting-started).

This example adds the vulnerability's SLA (`.vulnerability_sla`) after the project name:

```
curl -X GET "https://<YOUR-TENANT>/api/ss/vulnerabilities" -H "Host: <YOUR-TENANT>" -H "X-SSAPI-KEY: <YOUR-API-KEY>" -H "Content-Type: application/json" -H "Connection: close" | jq -r "(.vulnerabilities[] | [.vulnerability_id, .vulnerability_title, .vulnerability_created, .vulnerability_priority, .vulnerability_status, .vulnerability_status_updated, .vulnerability_affected_asset_name, if(try(.vulnerability_affected_assets)) then [.vulnerability_affected_assets[].asset.name] | join(\", \") else \"\" end, .vulnerability_retest, .vulnerability_project_name, .vulnerability_sla, .vulnerability_description, .vulnerability_attack_scenario, .vulnerability_remediation_recommendation, .vulnerability_steps_to_reproduce]) | @csv" > filtered_vulns.csv
```

### Add column names

To add a header row, put an array of column names before the data:

```
curl -X GET "https://<YOUR-TENANT>/api/ss/vulnerabilities" -H "Host: <YOUR-TENANT>" -H "X-SSAPI-KEY: <YOUR-API-KEY>" -H "Content-Type: application/json" -H "Connection: close" | jq -r "[\"Id\", \"Title\", \"Discovered\", \"Priority\", \"Status\", \"Status Last Updated\", \"Affected Asset\", \"Affected Assets\", \"Retest\", \"Project\", \"Description\", \"Attack Scenario\", \"Recommendation\", \"Steps To Reproduce\"], (.vulnerabilities[] | [.vulnerability_id, .vulnerability_title, .vulnerability_created, .vulnerability_priority, .vulnerability_status, .vulnerability_status_updated, .vulnerability_affected_asset_name, if(try(.vulnerability_affected_assets)) then [.vulnerability_affected_assets[].asset.name] | join(\", \") else \"\" end, .vulnerability_retest, .vulnerability_project_name, .vulnerability_description, .vulnerability_attack_scenario, .vulnerability_remediation_recommendation, .vulnerability_steps_to_reproduce]) | @csv" > filtered_vulns.csv
```

{% hint style="info" %}
**Note:** Keep the backslash before each quotation mark (`\"`) around the column names. Without it, jq may fail with a compile error.
{% endhint %}

### Filter the vulnerabilities

Use an Advanced Query Filter in the `q_vulnerability` parameter to export only some vulnerabilities. This example exports only Open vulnerabilities:

```
curl -G -X GET "https://<YOUR-TENANT>/api/ss/vulnerabilities" --data-urlencode "q_vulnerability={status:{$eq:\"Open\"}}" -H "Host: <YOUR-TENANT>" -H "X-SSAPI-KEY: <YOUR-API-KEY>" -H "Content-Type: application/json" -H "Connection: close" | jq -r "[\"Id\", \"Title\", \"Discovered\", \"Priority\", \"Status\", \"Status Last Updated\", \"Affected Asset\", \"Affected Assets\", \"Retest\", \"Project\", \"Description\", \"Attack Scenario\", \"Recommendation\", \"Steps To Reproduce\"], (.vulnerabilities[] | [.vulnerability_id, .vulnerability_title, .vulnerability_created, .vulnerability_priority, .vulnerability_status, .vulnerability_status_updated, .vulnerability_affected_asset_name, if(try(.vulnerability_affected_assets)) then [.vulnerability_affected_assets[].asset.name] | join(\", \") else \"\" end, .vulnerability_retest, .vulnerability_project_name, .vulnerability_description, .vulnerability_attack_scenario, .vulnerability_remediation_recommendation, .vulnerability_steps_to_reproduce]) | @csv" > filtered_vulns.csv
```

`-G` and `--data-urlencode` add the filter to the URL, encoded correctly.

{% hint style="info" %}
**Important:** On Linux and macOS, write `\$eq` instead of `$eq`. Otherwise the shell removes it and the filter doesn't work.
{% endhint %}

### Example: closed vulnerabilities and why they were closed

This example exports Closed vulnerabilities, with the reason, date and person from the last remediation note that contains "Issue Closed".

```
curl -G -X GET "https://<YOUR-TENANT>/api/ss/vulnerabilities" --data-urlencode "q_vulnerability={status:{$eq:\"Closed\"}}" -H "Content-Type: application/json" -H "Connection: close" -H "X-SSAPI-KEY: <YOUR-API-KEY>" | jq -r "[\"Vulnerability Id\", \"Created\", \"Priority\", \"Title\", \"Status\", \"Status Last Updated\", \"Affected Asset\", \"Affected Assets\", \"Project Name\", \"Project Id\", \"Last Closed Reason\", \"Last Closed On\", \"Last Closed By\"], (.vulnerabilities[] | [.vulnerability_id, .vulnerability_created, .vulnerability_priority, .vulnerability_title, .vulnerability_status, .vulnerability_status_updated, .vulnerability_affected_asset_name, if(try(.vulnerability_affected_assets)) then [.vulnerability_affected_assets[].asset.name] | join(\", \") else \"\" end, .vulnerability_project_name, .vulnerability_project_id, (last(.vulnerability_remediation_notes[] | select(.note | contains(\"Issue Closed\"))) | .note, .created, .created_by)]) | @csv" > filtered_vulns.csv
```

Example output:

| Vulnerability Id         | Created                  | Priority | Title               | Status | Status Last Updated      | Affected Asset            | Affected Assets                                                 | Project Name   | Project Id               | Last Closed Reason                 | Last Closed On           | Last Closed By |
| ------------------------ | ------------------------ | -------- | ------------------- | ------ | ------------------------ | ------------------------- | --------------------------------------------------------------- | -------------- | ------------------------ | ---------------------------------- | ------------------------ | -------------- |
| 65bc9d9a4534bd000e50db3f | 2024-02-02T07:45:30.179Z | Critical | Out-of-date Version | Closed | 2024-02-02T09:36:41.513Z | <https://attackforge.com> |                                                                 | Test Project 1 | 65af64ec07bd34000fbac60d | Issue Closed: Risk accepted        | 2024-02-02T09:36:41.513Z | Admin Test     |
| 65b56ceff8b879000f887c7e | 2024-01-27T20:51:59.346Z | Critical | Out-of-date Version | Closed | 2024-02-02T05:33:38.928Z |                           | <https://portal.attackforge.com>, <https://app.attackforge.com> | Test Project 1 | 65af64ec07bd34000fbac60d | Issue Closed: Issue has been fixed | 2024-02-02T05:33:38.928Z | Admin Test     |

## Troubleshooting

If the export doesn't work, run these checks in order to find the step that fails.

#### 1. Check jq is installed

```
jq
```

You should see jq's help text.

#### 2. Check cURL works and can pass JSON to jq

```
curl "https://api.github.com/repos/stedolan/jq/commits?per_page=5" | jq "."
```

You should see JSON data.

The jq repository has moved to `jqlang/jq`. This request now returns a redirect message, so step 3 fails. Use `https://api.github.com/repos/jqlang/jq/commits?per_page=5` in steps 2 to 4.

#### 3. Check @csv works

```
curl "https://api.github.com/repos/stedolan/jq/commits?per_page=5" | jq -r ".[0] | [.url] | @csv"
```

You should see the URL of a commit in the jq repository.

#### 4. Check you can write to a CSV file

```
curl "https://api.github.com/repos/stedolan/jq/commits?per_page=5" | jq -r ".[0] | [.url] | @csv" > output.csv
```

This should create `output.csv` in the current folder, containing the commit URL.

#### 5. Save AttackForge data as JSON

```
curl -X GET "https://<YOUR-TENANT>/api/ss/vulnerabilities" -H "Host: <YOUR-TENANT>" -H "X-SSAPI-KEY: <YOUR-API-KEY>" -H "Content-Type: application/json" -H "Connection: close" > vulns.json
```

This should create `vulns.json` in the current folder, containing your vulnerabilities. If it contains an error, check your hostname, API key and access to getVulnerabilities.

#### 6. Run jq on vulns.json

```
jq -r "(.vulnerabilities[] | [.vulnerability_created, .vulnerability_priority, .vulnerability_title, .vulnerability_status, .vulnerability_status_updated, .vulnerability_affected_asset_name, .vulnerability_retest, .vulnerability_project_name, .vulnerability_description, .vulnerability_attack_scenario, .vulnerability_remediation_recommendation, .vulnerability_steps_to_reproduce, .vulnerability_id]) | @csv" vulns.json
```

You should see CSV data.

#### 7. Export vulns.json to CSV

```
jq -r "(.vulnerabilities[] | [.vulnerability_created, .vulnerability_priority, .vulnerability_title, .vulnerability_status, .vulnerability_status_updated, .vulnerability_affected_asset_name, .vulnerability_retest, .vulnerability_project_name, .vulnerability_description, .vulnerability_attack_scenario, .vulnerability_remediation_recommendation, .vulnerability_steps_to_reproduce, .vulnerability_id]) | @csv" vulns.json > filtered_vulns.csv
```

This should create `filtered_vulns.csv` in the current folder.

If step 7 works, the full command should work too:

```
curl -X GET "https://<YOUR-TENANT>/api/ss/vulnerabilities" -H "Host: <YOUR-TENANT>" -H "X-SSAPI-KEY: <YOUR-API-KEY>" -H "Content-Type: application/json" -H "Connection: close" | jq -r "(.vulnerabilities[] | [.vulnerability_id, .vulnerability_title, .vulnerability_created, .vulnerability_priority, .vulnerability_status, .vulnerability_status_updated, .vulnerability_affected_asset_name, if(try(.vulnerability_affected_assets)) then [.vulnerability_affected_assets[].asset.name] | join(\", \") else \"\" end, .vulnerability_retest, .vulnerability_project_name, .vulnerability_description, .vulnerability_attack_scenario, .vulnerability_remediation_recommendation, .vulnerability_steps_to_reproduce]) | @csv" > filtered_vulns.csv
```

## Tips

* **Save the JSON first.** Save the API response to a file (troubleshooting step 5), then experiment with jq on the file. You won't call the API every time you change a column.
* **Filter in the API, not in jq.** A `q_vulnerability` filter returns less data, so exports are faster.
* **Always add column names.** A header row makes the CSV easier to read and import.
* **Keep your API key out of scripts.** Read it from an environment variable instead of typing it into the command.
* **Watch the quoting.** Command Prompt, PowerShell and bash treat quotes and `$` differently. If jq reports a compile error, check the escaped quotes first.
* **Open the CSV with the right encoding.** If special characters look wrong in Excel, import the file as UTF-8.
* **Use AI for one-off exports.** For a quick table or spreadsheet, asking an AI assistant through [AI MCP](https://support.attackforge.com/app/automations-and-integrations/ai-mcp-and-skills) can be faster than writing jq.

## FAQ

**Can I export data other than vulnerabilities?** Yes. The same approach works with any Self-Service API method. Change the URL and the fields to match that method's response.

**Which fields can I export?** Any field the API returns. See the method's documentation in the [API documentation](https://docs.attackforge.com/rest-api/pages/getting-started).

**Why is my CSV empty?** Check that you have access to getVulnerabilities, that your API key and hostname are correct, and that your filter matches some vulnerabilities. Then work through the troubleshooting steps.

**Why do I get a jq compile error?** Usually the quotation marks around column names or strings aren't escaped (`\"`), or your shell has changed the command. See Choose where to run the commands.

**Why does my filter return every vulnerability, or none?** On Linux and macOS, `$eq` inside double quotes is read as a shell variable. Write `\$eq` instead.

**How are grouped assets exported?** The Affected Assets column lists each asset's name, separated by a comma.

**Can I schedule the export?** Yes. Save the command in a script, and run it with your scheduler, such as cron or Windows Task Scheduler.

## Related pages

* [Self-Service RESTful API](https://support.attackforge.com/app/automations-and-integrations/self-service-restful-api): get access to API methods and create your API key.
* [API documentation](https://docs.attackforge.com/rest-api/pages/getting-started): every API method and its fields.
* [Advanced Query Filter](https://support.attackforge.com/app/automations-and-integrations/self-service-restful-api/advanced-query-filter): the filter syntax used in `q_vulnerability`.
* [AI MCP and Skills](https://support.attackforge.com/app/automations-and-integrations/ai-mcp-and-skills): ask an AI assistant to build tables and spreadsheets from your data.
* [Report automation](https://support.attackforge.com/app/automations-and-integrations/report-automation): generate reports automatically.
* [jq manual](https://jqlang.org/manual/): everything jq can do.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://support.attackforge.com/app/automations-and-integrations/self-service-restful-api/exporting-to-csv.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
