Encrypted API Request (Recommended) #
“secret_key” is the admin’s “token” in API service settings Content-Type: application/x-www-form-urlencoded
GET Request #
/echart/dataset_api/?visitor=xxx&token=xxx&type=xxx&stamp=xxxxx¶m={"xx":"xxx"}
Parameters:
visitor: username
type: dataset ID
stamp: timestamp (milliseconds since 1970)
token: SHA1(secret_key + stamp + visitor + type)
param: query parameters (optional), JSON string
Response:
{
"data": [[]],
"result": "success",
"maxpg": 1,
"pg": 1
}
data: 2D array, first row is headerresult: success or errormaxpg/pg: Fixed at 1 for GET (no pagination)
POST Request #
For backend scheduled data sync. Use GET for queries.
url: /echart/dataset_api/
data: {
"visitor": "xxx",
"token": "xxx",
"stamp": xxxxx,
"type": "xxx",
"pagesize": "xxx",
"pg": "xxx",
"param": '{"xxx":"xxxx"}'
}
Response:
{
"data": [[]],
"status": 200,
"msg": "success",
"maxpg": xxx,
"pg": xx,
"casheflag": xx,
"total": xx
}
POST supports pagination. First page has headers, subsequent pages don’t. POST uses cache for pagination - parameters won’t work if cache is hit. Use GET for small datasets. Don’t request large data volumes; use limit/offset parameters for pagination.
Python Example #
def post_data():
import requests, hashlib, json
url = 'http://localhost:8000/echart/dataset_api/'
visitor = 'xxx'
key = 'xxxxxx'
id = 123
stamp = int(time.time() * 1000)
param = json.dumps({"xxx": "xxxx"})
token = hashlib.sha1(f"{key}{stamp}{visitor}{id}".encode('utf-8')).hexdigest()
data = {"visitor": visitor, "token": token, "stamp": stamp, "type": id, "param": param}
res = requests.post(url, data=data, headers={'Content-Type': 'application/x-www-form-urlencoded'})
print(res.json())
Unencrypted Request (Simple but Insecure) #
GET: /echart/dataset_api/?visitor=xxx&token=xxx&type=dataset_name_or_id
POST: /echart/dataset_api/ with same data fields