如何通过Qlik Engine API按指定时间范围获取数据及相关疑问
Hey there! I remember struggling with similar hurdles when I first dipped my toes into the Qlik Engine API, so let's work through your questions one by one:
The core solution here is adding a filter condition directly to your HyperCube definition to narrow down the date range. Let's use your "last 7 days daily exposure" example to show how it works:
Assuming your date field is named Date and your exposure metric is calculated as Sum(Exposure), you can add a qWhere clause to your date dimension to enforce the time filter. Here's a sample JSON request you can adapt:
{ "jsonrpc": "2.0", "id": 1, "method": "CreateSessionObject", "params": [ { "qInfo": { "qId": "", "qType": "HyperCube" }, "qHyperCubeDef": { "qDimensions": [ { "qDef": { "qFieldDefs": ["Date"], "qFieldLabels": ["日期"], "qWhere": { "qExpr": { "qString": "Date >= Today()-6" } } }, "qNullSuppression": true } ], "qMeasures": [ { "qDef": { "qDef": "Sum(Exposure)", "qLabel": "曝光量" } } ], "qInitialDataFetch": [ { "qTop": 0, "qLeft": 0, "qHeight": 100, "qWidth": 2 } ] } } ] }
- For "last week", adjust the
qWhereexpression toWeek(Date) = Week(Today())-1(tweak this withWeekName(Date)if you need consistent week boundary matching based on your system settings). - For "last 4 days", swap the expression to
Date >= Today()-3.
You can also create a standalone filter object to control time ranges, but adding the qWhere directly to the dimension is more straightforward for simple use cases.
Here are my go-to resources when working with the Engine API:
- Official Engine API Documentation: Focus heavily on the HyperCube sections—they break down every parameter, including filtering logic, dimension/measure configuration, and data fetching workflows.
- Qlik Dev Hub API Explorer: If you have access to a Qlik Sense server, this tool lets you build, test, and debug WebSocket requests in real time. It's perfect for experimenting with different payloads and seeing immediate results.
- Qlik Community Engine API Section: Tons of real-world examples from fellow developers—you'll find solutions for common scenarios like time range filtering, complex HyperCube setups, and edge-case handling.
- Official Qlik Example Repositories: These include full code samples covering everything from opening an app via WebSocket to fetching and processing HyperCube data, which is great for learning by example.
qlik.OpenApp JavaScript Library qlik.OpenApp is part of the Qlik Sense JavaScript SDK (often referred to as qlik.js). You don't need to install it via npm—instead, load it directly from your Qlik Sense server:
<script src="https://your-qlik-server-url/resources/assets/external/qlik-js/qlik.js"></script>
Once loaded, initialize the connection first before calling openApp:
const qlikConfig = { host: 'your-qlik-server-url', prefix: '/', port: 443, isSecure: true }; window.qlik.setOnError(err => console.error(err)); window.qlik.connect(qlikConfig); // Now you can open your app const app = window.qlik.openApp('your-app-unique-id');
If you prefer sticking to raw WebSocket requests (no SDK), you can send an OpenDoc request directly:
{ "jsonrpc": "2.0", "id": 2, "method": "OpenDoc", "params": ["your-app-id", "", "", "", false] }
内容的提问来源于stack exchange,提问作者kishore

