# Export the data of a generic object

Export the data of a generic object by using the [ExportData method](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineJSONAPI/Content/service-genericobject-exportdata.htm).

## Examples

Example 1:

[](https://help.qlik.com/en-US/sense-developer/Subsystems/EngineAPI/Content/Sense_EngineAPI/WorkingWithAppsAndVisualizations/ExportData/export-data-GO.htm)

#### The goal is to export a chart to a csv file.

1. Create a chart with one dimension Country and one measure Count(Holes).

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "CreateSessionObject",
  "handle": 1,
  "params": [
    {
      "qInfo": {
        "qId": "",
        "qType": "Chart"
      },
      "qHyperCubeDef": {
        "qStateName": "$",
        "qDimensions": [
          {
            "qLibraryId": "",
            "qNullSuppression": false,
            "qDef": {
              "qGrouping": "N",
              "qFieldDefs": [
                "Country"
              ],
              "qFieldLabels": [
                "Country label"
              ]
            }
          }
        ],
        "qMeasures": [
          {
            "qLibraryId": "",
            "qSortBy": {
              "qSortByState": 0,
              "qSortByFrequency": 0,
              "qSortByNumeric": 0,
              "qSortByAscii": 0,
              "qSortByLoadOrder": 1,
              "qSortByExpression": 0,
              "qExpression": {
                "qv": ""
              }
            },
            "qDef": {
              "qLabel": "",
              "qDescription": "",
              "qTags": [
                "tags"
              ],
              "qGrouping": "N",
              "qDef": "Count(Holes)"
            }
          },
          {
            "qLibraryId": "",
            "qSortBy": {
              "qSortByState": 0,
              "qSortByFrequency": 0,
              "qSortByNumeric": 0,
              "qSortByAscii": 0,
              "qSortByLoadOrder": 1,
              "qSortByExpression": 0,
              "qExpression": {
                "qv": ""
              }
            },
            "qDef": {
              "qLabel": "",
              "qDescription": "",
              "qTags": [
                "tags"
              ],
              "qGrouping": "N",
              "qDef": ""
            }
          }
        ],
        "qInitialDataFetch": [
          {
            "qTop": 0,
            "qLeft": 0,
            "qHeight": 3,
            "qWidth": 1
          },
          {
            "qTop": 0,
            "qLeft": 0,
            "qHeight": 0,
            "qWidth": 0
          },
          {
            "qTop": 0,
            "qLeft": 0,
            "qHeight": 0,
            "qWidth": 0
          }
        ]
      }
    }
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "qReturn": {
      "qType": "GenericObject",
      "qHandle": 2
    }
  },
  "change": [
    2
  ]
}
```

The chart is created and has 2 as a handle.

2. Export the data of the chart to a CSV file (qFileType is CSV\_C). The handle of the request is 2 because the handle of the chart is 2. The path to the definition of the chart is /qHyperCubeDef (qPath is /qHyperCubeDef). The name of the exported file is CsvUTF8.csv (in qFileName).

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "ExportData",
  "handle": 2,
  "params": [
    "CSV_C",
    "/qHyperCubeDef",
    "CsvUTF8.csv"
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "qUrl": "/Exports/CsvUTF8(a98f4186-2d81-4be8-837a-911e41e8377a).csv"
  }
}
```

The data of the chart is exported to a CSV file.

The file is renamed to what is passed as argument (in qFileName) by the browser after download. This is done by sending content-disposition in the header of the response from HTTP Get on the URL returned by the ExportData call.

Chart as in the example:

![Example bar chart with Country on the X axis and Holes on the Y axis](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineAPI/Content/Resources/Images/ui_gen_ExampleQVCPChartForExportData_go.png)

Exported data:

![Exported data in CSV format, displayed as a list](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineAPI/Content/Resources/Images/ui_gen_ExampleQVCPCSVFileExport_go.png)

Example 2:

[](https://help.qlik.com/en-US/sense-developer/Subsystems/EngineAPI/Content/Sense_EngineAPI/WorkingWithAppsAndVisualizations/ExportData/export-data-GO.htm)

#### The goal is to export the data of a pivot table to an xlsx file.

Prerequisite:

A pivot table is created. The handle of the pivot table is 2.

The hypercube is defined as follows:

"qHyperCubeDef": { "qDimensions": [ { "qLibraryId": "", "qDef": { "qFieldDefs": [ "CategoryName" ], "qFieldLabels": [ "" ], "qSortCriterias": [ { "qSortByLoadOrder": 0, "qSortByAscii": 1 } ], "qReverseSort": false } }, { "qLibraryId": "", "qDef": { "qFieldDefs": [ "ProductName" ], "qFieldLabels": [ "" ], "qSortCriterias": [ { "qSortByLoadOrder": 0, "qSortByAscii": 1 } ], "qReverseSort": false } }, { "qLibraryId": "", "qDef": { "qFieldDefs": [ "City" ], "qFieldLabels": [ "" ], "qSortCriterias": [ { "qSortByLoadOrder": 0, "qSortByAscii": 1 } ], "qReverseSort": false } }, { "qLibraryId": "", "qDef": { "qFieldDefs": [ "Customer" ], "qFieldLabels": [ "" ], "qSortCriterias": [ { "qSortByLoadOrder": 0, "qSortByAscii": 1 } ], "qReverseSort": false } } ], "qMeasures": [ { "qLibraryId": "", "qDef": { "qLabel": "", "qDef": "Sum(OrderTotal)" } }, { "qLibraryId": "", "qDef": { "qLabel": "", "qDef": "" } } ], "qMode": "EQ\_DATA\_MODE\_PIVOT", "qAlwaysFullyExpanded": true, "qInitialDataFetch": [ { "qTop": 0, "qLeft": 0, "qHeight": 100, "qWidth": 100 } ], "qSuppressZero": true, "qSuppressMissing": true, "qNoOfLeftDims": 3, "qInterColumnSortOrder": [ 0, 1, 3, 2 ] }

Regarding the above definition, the hypercube has the following properties:

* Is a pivot table ("qMode": "EQ\_DATA\_MODE\_PIVOT")

* Has four dimensions defined in the following order: CategoryName, ProductName, City and Customer.

* The measure is Sum(OrderTotal).

* The inter column sort order is [0,1, 3, 2].

* Contains 3 left dimensions ("qNoOfLeftDims": 3).

* The cells are always fully expanded ("qAlwaysFullyExpanded": true).

* CategoryName, ProductName and Customer are left dimensions (according to the inter column sort order and the number of left dimensions).

* City is a top dimension (according to the inter column sort order (qInterColumnSortOrder ) and the number of left dimensions (qNoOfLeftDims)).

Export the data from the pivot table to an xlsx file (qFileType is OOXML) using the [ExportData method](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineJSONAPI/Content/service-genericobject-exportdata.htm).

In the example below, the handle of the request is 2 because the handle of the pivot table is 2. The path to the definition of the pivot table is: /qHyperCubeDef (qPath is /qHyperCubeDef).

The client sends:

{ "jsonrpc": "2.0", "id": 3, "method": "ExportData", "handle": 2, "params": [ "OOXML", "/qHyperCubeDef" ] }

The engine returns:

{ "jsonrpc": "2.0", "id": 3, "result": { "qUrl": "/Exports/fb0a0877-a247-4800-b3c8-bf2f76bb5757.xlsx" } }

The data is exported to axlsx file.

Exported data:

![Example data exported as a spreadsheet, hierarchy maintained](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineAPI/Content/Resources/Images/ui-gen-example-pivot-file-export.png)