POST请求 #
url: /echart/dataset_api/
Content-Type: application/x-www-form-urlencoded
请求参数data #
{
"visitor":"xxx",
"token":"xxx",
"stamp":"xxxxx",
"type":"xxx",
"ds":[["A","B"],["a1","b1"],["a2","b2"]],
"update":0
}
参数说明 #
visitor: 用户名
type: 接口数据集ID
stamp: 时间戳(1970年1月1日到生成时间的毫秒数)
token: 采用sha1加密, token=SHA1(秘钥 + stamp + visitor + type)
update: 0表示新增, 1表示数据更新
ds: 二维数组 或 参考数据填报或数据更新的格式要求
“秘钥"即管理员在API服务设定中的"token”
返回格式 #
{
"status": 200,
"msg": "success"
}
调用样列参考 #
def post_data():
import requests
import hashlib
url='http://localhost:8000/echart/dataset_api/'
visitor = 'xxx'
key = 'xxxxxx'
chart_type = 123
ContentType="application/x-www-form-urlencoded"
stamp = int(time.time() * 1000)
token = hashlib.sha1(f"{key}{stamp}{visitor}{chart_type}".encode('utf-8')).hexdigest()
ds= json.dumps([["A", "B"],["a1", "b1"],["a2", "b2"]])
data={
"visitor": visitor,
"token": token,
"stamp": stamp,
"type": chart_type,
"ds": ds
}
res = requests.post(url, data=data, headers={'Content-Type': ContentType})
print(res.json())
接口配置 #
- 新建数据集
- 写入相关配置
dataset={
"table":"表名(字段1,字段2....)",
"preSql":["truncate table abc"],
"postSql":["insert into xxx select ...."]
}
- 相关权限管理参考“数据服务设定”
文件上传API #
中台版可以在“数据管道”–>“上传配置“ 中进行设定后 ,使用API上传文件的方式导入
POST url: POST /etl/api/upload_file_api/
POST 数据:
data = {"type":"xxx",
"token" : "xxx",
"visitor":"xxxx",
"mail":"xxx@xxxx,xxx@xx", #可选,上传后邮件结果
}
:return: {"data": message,"result": "error"}
当data中增加参数(可选):
"filename":"xxxx" #只重新处理已上传的文件不会进行文件处理
以python代码为例
def post_file():
import requests
import hashlib
url='/etl/api/upload_file_api/'
visitor = 'xxx'
key = 'xxxxxx'
name = 'xxx'
mail = "xxx@xxxx,xxx@xx" #可选,上传后邮件结果
ContentType="application/x-www-form-urlencoded"
stamp = int(time.time() * 1000)
token = hashlib.sha1(f"{key}{stamp}{visitor}{chart_type}".encode('utf-8')).hexdigest()
data={
"visitor": visitor,
"token": token,
"stamp": stamp,
"type": name,
"mail":mail
}
files = {'file': open('xxxx.xlsx', 'rb')}
#上传,https可能需要参数 verify=False
response = requests.post(url, files=files, data=data)
if response.status_code == 200:
response = response.json()
elif response.status_code == 504:
response = {"result":"timeout","data":"Pls wait for mail"}
else:
response = {"result": "error","data": "some thing wrong"}
if response['result'] == 'error':
raise Exception('Upload Error')
return response