GitHub user dosubot[bot] added a comment to the discussion: REST API Endpoint 
for Downloading Superset Charts in CSV/Excel Format

<!-- Answer -->
Here’s an example of a JSON payload tailored to a specific chart type (e.g., a 
"deck_polygon" chart) for the /api/v1/chart/data endpoint, along with an 
explanation of the mandatory parameters.

---

### Example: deck_polygon Chart

```json
{
  "datasource": "9__table",
  "queries": [
    {
      "columns": ["population", "area", "contour"],
      "metrics": ["count"],
      "filters": [
        {
          "col": "contour",
          "op": "IS NOT NULL",
          "val": ""
        }
      ],
      "row_limit": 10000,
      "granularity": null,
      "time_range": " : "
    }
  ],
  "result_format": "csv",
  "result_type": "full"
}
```

- To export as Excel, set `"result_format": "xlsx"`.

---

### Mandatory Parameters

When using `/api/v1/chart/data`, the following parameters are required in the 
JSON payload:

- **datasource**: The unique identifier for your datasource, in the format 
`<id>__<type>` (e.g., `"9__table"` for table with ID 9) 
[[source]](https://github.com/apache/superset/blob/master/superset/charts/data/api.py).
- **queries**: An array of query objects. Each object should specify at least 
the columns, metrics, and any filters relevant to your chart.
- **result_format**: The desired output format. Use `"csv"` for CSV or `"xlsx"` 
for Excel 
[[source]](https://github.com/apache/superset/blob/master/superset/charts/data/api.py).
- **result_type**: The result type, typically `"full"` for a complete export 
[[source]](https://github.com/apache/superset/blob/master/superset/charts/data/api.py).

Other fields inside each query (like `columns`, `metrics`, `filters`, 
`row_limit`, etc.) depend on your chart’s configuration and the data you want 
to retrieve.

---

#### Reference for a more complex chart payload

For more complex charts (like "deck_polygon"), the payload may include 
additional fields such as `viz_type`, `slice_id`, `granularity_sqla`, 
`time_grain_sqla`, `adhoc_filters`, and more, depending on the chart’s 
requirements. You can see an example structure in the [Superset demo 
payload](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-demo/storybook/stories/plugins/legacy-preset-chart-deckgl/Polygon/payload.js).

---

If you have a specific chart type or configuration in mind, let me know and I 
can tailor the example further!


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://go.dosu.dev/dosubot), mention @dosu-bot.*

---
<sup>Help Dosu learn! Give it feedback: [Great 
Response](https://app.dosu.dev/response-feedback/6f9bf7e4-c4ea-4816-9911-729f99a9ad29?feedback_type=great_response)
 | [Irrelevant 
Answer](https://app.dosu.dev/response-feedback/6f9bf7e4-c4ea-4816-9911-729f99a9ad29?feedback_type=irrelevant_answer)
 | [Incorrect 
Sources](https://app.dosu.dev/response-feedback/6f9bf7e4-c4ea-4816-9911-729f99a9ad29?feedback_type=incorrect_sources)
 | [Too 
Verbose](https://app.dosu.dev/response-feedback/6f9bf7e4-c4ea-4816-9911-729f99a9ad29?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/6f9bf7e4-c4ea-4816-9911-729f99a9ad29?feedback_type=hallucination)
 | [Bug 
Report](https://app.dosu.dev/response-feedback/6f9bf7e4-c4ea-4816-9911-729f99a9ad29?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/6f9bf7e4-c4ea-4816-9911-729f99a9ad29?feedback_type=other)</sup>


GitHub link: 
https://github.com/apache/superset/discussions/33574#discussioncomment-13246316

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to