title: Export visualization data using Qlik Engine JSON API
body: <p>Our organization uses Qlik Sense Enterprise and we are looking to automate the download process of the data used for visualizations (format can be excel or csv) instead of the manual process which leads to the following (cropped screenshot shown):</p>
  <p><a href="https://i.stack.imgur.com/qXx2H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qXx2H.png" alt="From qlik sense portal" /></a></p>
  <p>For our use case, lets assume there is only one app which has one sheet inside and that sheet has 3 visualizations.</p>
  <p>I have written a python script which currently has been connected to the localhost and I am able to retrieve the app_id, sheet_id and the id of the 3 charts present using Qlik Engine JSON API. The code works in the following manner:</p>
  <ol>
  <li>Fetch the doc_list (app_list)</li>
  <li>Select the app, since we have only one app we choose index as 0</li>
  <li>Create a session object (I saw Qlik Engine on Dev Hub exhibiting this behavior which is why I executed this step)</li>
  <li>Get the layout of the app</li>
  <li>Select the sheet, since we have one sheet we choose index as 0</li>
  <li>Iterate through the visualizations and print their names</li>
  </ol>
  <p>I have provided the code below for your reference as well as the pastebin link can be accessed <a href="https://pastebin.com/VdDBMzAJ" rel="nofollow noreferrer">here</a></p>
  <pre><code>import requests
  import websocket, ssl
  import json,  csv
  import os, time
  from pprint import pprint 
   
  #Connecting to the server. The lines below will be replaced by the certificates and headers for enterprise usage later
  ws = websocket.WebSocket()
  ws.connect(&quot;ws://localhost:4848/app/&quot;)
   
  #For getting the doc (app) list
  doclist_req = {
      &quot;handle&quot;: -1,
      &quot;method&quot;: &quot;GetDocList&quot;,
      &quot;params&quot;: [],
      &quot;outKey&quot;: -1,
      &quot;id&quot;: 1
  }
   
  ws.send(json.dumps(doclist_req))
  result = ws.recv()
  ws.send(json.dumps(doclist_req))
  result = ws.recv()
  result_json = json.loads(result)
  print(result_json)
  print()
   
  #For opening the doc (app)
  app_req = {
      &quot;jsonrpc&quot;: &quot;2.0&quot;,
      &quot;method&quot;: &quot;OpenDoc&quot;,
      &quot;handle&quot;: -1,
      &quot;params&quot;: [
          #Can iterate if multiple apps are there
          #Since only one app was present we used the index 0
          result_json['result']['qDocList'][0]['qDocId']
      ],
      &quot;outKey&quot;: -1,
      &quot;id&quot;: 2
  }
   
  #The first call seems to be for establishing the connection and second to actually send the request body
  ws.send(json.dumps(app_req))
  result = ws.recv()
  ws.send(json.dumps(app_req))
  result = ws.recv()
  result_json = json.loads(result)
  print(result_json)
  print()
  app_req_handle = result_json['result']['qReturn']['qHandle']
   
  #For creating the session object necessary for fetching dimensions, fields, etc.
  session_req = {
      &quot;jsonrpc&quot;: &quot;2.0&quot;,
      &quot;method&quot;: &quot;CreateSessionObject&quot;,
      &quot;handle&quot;: app_req_handle,
      &quot;params&quot;: [
          {
              &quot;qInfo&quot;: {
                  &quot;qType&quot;: &quot;SheetList&quot;
              },
              &quot;qAppObjectListDef&quot;: {
                  &quot;qType&quot;: &quot;sheet&quot;,
                  &quot;qData&quot;: {
                      &quot;title&quot;: &quot;/qMetaDef/title&quot;,
                      &quot;description&quot;: &quot;/qMetaDef/description&quot;,
                      &quot;thumbnail&quot;: &quot;/thumbnail&quot;,
                      &quot;cells&quot;: &quot;/cells&quot;,
                      &quot;rank&quot;: &quot;/rank&quot;,
                      &quot;columns&quot;: &quot;/columns&quot;,
                      &quot;rows&quot;: &quot;/rows&quot;
                  }
              }
          }
      ],
      &quot;outKey&quot;: -1,
      &quot;id&quot;: 3
  }
   
  ws.send(json.dumps(session_req))
  result = ws.recv()
  ws.send(json.dumps(session_req))
  result = ws.recv()
  result_json = json.loads(result)
  print(result_json)
  print()
  session_req_handle = result_json['result']['qReturn']['qHandle']
   
  #For fetching the layout of the sheets
  layout_req = {
      &quot;jsonrpc&quot;: &quot;2.0&quot;,
      &quot;method&quot;: &quot;GetLayout&quot;,
      &quot;handle&quot;: session_req_handle,
      &quot;params&quot;: [],
      &quot;outKey&quot;: -1,
      &quot;id&quot;: 4
  }
   
  ws.send(json.dumps(layout_req))
  result = ws.recv()
  ws.send(json.dumps(layout_req))
  result = ws.recv()
  result_json = json.loads(result)
  print(result_json)
  print()
   
  #Since only one sheet was present we used the index 0
  list_of_charts = result_json['result']['qLayout']['qAppObjectList']['qItems'][0]['qData']['cells']
  for chart in list_of_charts:
      print(chart['name'])
  print()
   
  ws.close()
  </code></pre>
  <p>I have explored a lot of pages on the Qlik community as well as SO and ExportData seems to be the way to go but I am not able to write the correct JSON request for it. For reference, the output I get in my terminal on executing the python script is given below.  I am quite new to this and I would be very thankful for any help from all of you.</p>
  <blockquote>
  <p>{'jsonrpc': '2.0', 'id': 1, 'result': {'qDocList': [{'qDocName': 'Test_2.qvf', 'qConnectedUsers': 0, 'qFileTime': 44188.190983796296, 'qFileSize': 851968, 'qDocId': 'C:\Users\mohdm\Documents\Qlik\Sense\Apps\Test_2.qvf', 'qMeta': {'hassectionaccess': False, 'encrypted': False}, 'qLastReloadTime': '2020-12-22T19:12:22.245Z', 'qTitle': 'Test_2', 'qThumbnail': {}}]}} <br/><br/> {'jsonrpc': '2.0', 'id': 2, 'result': {'qReturn': {'qType': 'Doc', 'qHandle': 1, 'qGenericId': 'C:\Users\mohdm\Documents\Qlik\Sense\Apps\Test_2.qvf'}}, 'change': <a href="https://i.stack.imgur.com/qXx2H.png" rel="nofollow noreferrer">1</a>} <br/><br/>{'jsonrpc': '2.0', 'id': 3, 'result': {'qReturn': {'qType': 'GenericObject', 'qHandle': 2, 'qGenericType': 'SheetList', 'qGenericId': '4b344780-a350-48db-8b65-27bb5a2c62b2'}}, 'change': <a href="https://i.stack.imgur.com/qXx2H.png" rel="nofollow noreferrer">1</a>} <br/><br/> {'jsonrpc': '2.0', 'id': 4, 'result': {'qLayout': {'qInfo': {'qId': '4b344780-a350-48db-8b65-27bb5a2c62b2', 'qType': 'SheetList'}, 'qMeta': {'privileges': ['read', 'update', 'delete', 'exportdata']}, 'qSelectionInfo': {}, 'qAppObjectList': {'qItems': [{'qInfo': {'qId': '8a0f6a01-ef89-4d65-821f-371c26208dcf', 'qType': 'sheet'}, 'qMeta': {'privileges': ['read', 'update', 'delete', 'exportdata'], 'title': 'Sheet_1', 'description': ''}, 'qData': {'rank': None, 'thumbnail': {'qStaticContentUrl': {}}, 'columns': 24, 'rows': 12, 'cells': [{'name': 'kfxNpV', 'type': 'auto-chart', 'col': 0, 'row': 0, 'colspan': 15, 'rowspan': 6, 'bounds': {'y': 0, 'x': 0, 'width': 62.5, 'height': 50}}, {'name': 'qHzmARQ', 'type': 'qlik-barplus-chart', 'col': 0, 'row': 6, 'colspan': 21, 'rowspan': 6, 'bounds': {'y': 50, 'x': 0, 'width': 87.5, 'height': 50}}, {'name': 'BXBQmw', 'type': 'auto-chart', 'col': 15, 'row': 0, 'colspan': 9, 'rowspan': 6, 'bounds': {'y': 0, 'x': 62.5, 'width': 37.5, 'height': 50}}], 'title':
  'Sheet_1', 'description': ''}}]}}}} <br/><br/> kfxNpV <br/> qHzmARQ <br/> BXBQmw</p>
  </blockquote>
  <p>I had originally posted this question at <a href="https://community.qlik.com/t5/Qlik-Sense-Integration-Extensions-APIs/Export-visualization-data-using-Qlik-Engine-JSON-API/m-p/1770208#M13665" rel="nofollow noreferrer">Qlik community</a> as well but it didn't get a response.</p>