数据导入导出操作

数据的导入、导出任务一旦成功建立,结果将以邮件的形式发送到创建任务的用户邮箱里。

数据导出

接口

POST https://cloud.minapp.com/oserve/v1.5/table/:table_id/export/

其中 table_id 是数据表的 ID

请求参数

参数类型必填说明
file_typeString导出文件的格式,支持 csv、json 格式
modeString导出任务的模式
whereObject导出数据的查询条件
exclude_keysArray导出数据时排除的字段列表
include_keysArray导出数据时包含的字段列表
order_byArray导出数据时需要进行排序的字段列表
csv_customize_headersArray导出数据为 CSV 时,可指定列名
timestamp_convert_keysArray导出数据时需要进行时间类型转换的字段列表

导出任务支持两种模式:

说明
all导出全部数据
part导出部分数据

order_by 排序支持指定正序或者倒序,在字段前面加 "-" 表示倒序,目前支持排序的字段类型有 5 种,分别是 {"boolean", "date", "integer", "number", "string"}

代码示例

  1. curl -X POST \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. -d '{
  5. "file_type": "csv",
  6. "mode": "all"
  7. }' \
  8. https://cloud.minapp.com/oserve/v1.5/table/:table_id/export/
  1. var request = require('request')
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1.5/table/:table_id/export/',
  4. method: 'POST',
  5. headers: {
  6. Authorization: `Bearer ${token}`
  7. },
  8. json: { // 指定 data 以 "Content-Type": 'application/json' 传送
  9. file_type: 'csv',
  10. mode: 'all'
  11. }
  12. }
  13. request(opt, function (err, res, body) {
  14. console.log(res.statusCode)
  15. })
  1. <?php
  2. $table_id = 1; // 数据表的 ID
  3. $url = "https://cloud.minapp.com/oserve/v1.5/table/{$table_id}/export/";
  4. $param = array(
  5. 'file_type' => 'csv',
  6. "mode" => "all"
  7. );
  8. $ch = curl_init();
  9. $header = array(
  10. "Authorization: Bearer {$token}",
  11. 'Content-Type: application/json; charset=utf-8'
  12. );
  13. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  14. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  15. curl_setopt($ch, CURLOPT_URL,$url);
  16. curl_setopt($ch, CURLOPT_POST,true);
  17. curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($param));
  18. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,true);
  20. $res['response'] = curl_exec($ch); // 反馈结果
  21. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  22. curl_close($ch);

返回示例

  1. {
  2. "status": "ok",
  3. "job_id": "xxxxxxxxxxxxxxxxxxxx"
  4. }

状态码说明

201: 导出任务创建成功

400: 1min 内多次创建任务;数据量超过 100W;数据格式错误

获取单个导出任务信息

接口

GET https://cloud.minapp.com/oserve/v1.5/table/:table_id/export/:job_id/

其中 :table_id 需替换为数据表 ID,:job_id 需替换为建立导出任务时返回的 job_id。

返回参数说明

字段名称类型说明
job_idString导出任务 ID
statusString任务状态,等待处理:pending、正在处理:ready、已完成:finish
operationString操作类型,固定为:export
file_nameString文件名
file_typeString文件类型
download_urlString下载链接
created_atInteger任务创建时间戳
updated_atInteger最近一次任务更新时间戳

代码示例

  1. curl -X GET \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1.5/table/1/export/RcnyXjPH8zLSsUYrIlPsG5qnBERYFrGF/
  1. var request = require('request')
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1.5/table/1/export/RcnyXjPH8zLSsUYrIlPsG5qnBERYFrGF/',
  4. method: 'GET',
  5. headers: {
  6. Authorization: `Bearer ${token}`
  7. }
  8. }
  9. request(opt, function (err, res, body) {
  10. console.log(body)
  11. })
  1. <?php
  2. $table_id = 1; // 数据表的 ID
  3. $job_id = 'RcnyXjPH8zLSsUYrIlPsG5qnBERYFrGF'; // 导出任务 ID
  4. $url = "https://cloud.minapp.com/oserve/v1.5/table/{$table_id}/export/{$job_id}/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  16. $res['response'] = curl_exec($ch); // 反馈结果
  17. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  18. curl_close($ch);

返回示例

  1. {
  2. "created_at": 1574405175,
  3. "download_url": null,
  4. "file_name": null,
  5. "file_type": "json",
  6. "job_id": "RcnyXjPH8zLSsUYrIlPsG5qnBERYFrGF",
  7. "operation": "export",
  8. "status": "pending",
  9. "updated_at": 1574405175
  10. }

状态码说明

200: 成功

404: 找不到 job_id 对应的任务

批量获取导出任务信息

接口

GET https://cloud.minapp.com/oserve/v1.5/table/:table_id/export/

其中 :table_id 需替换为你的数据表 ID。

代码示例

  1. curl -X GET \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1.5/table/1/export/
  1. var request = require('request')
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1.5/table/1/export/',
  4. method: 'GET',
  5. headers: {
  6. Authorization: `Bearer ${token}`
  7. }
  8. }
  9. request(opt, function (err, res, body) {
  10. console.log(body)
  11. })
  1. <?php
  2. $table_id = 1; // 数据表的 ID
  3. $url = "https://cloud.minapp.com/oserve/v1.5/table/{$table_id}/export/";
  4. $ch = curl_init();
  5. $header = array(
  6. "Authorization: Bearer {$token}",
  7. 'Content-Type: application/json; charset=utf-8'
  8. );
  9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  11. curl_setopt($ch, CURLOPT_URL, $url);
  12. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  15. $res['response'] = curl_exec($ch); // 反馈结果
  16. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  17. curl_close($ch);

返回示例

  1. {
  2. "meta": {
  3. "limit": 20,
  4. "next": null,
  5. "offset": 0,
  6. "previous": null,
  7. "total_count": 1
  8. },
  9. "objects": [
  10. {
  11. "created_at": 1574405175,
  12. "download_url": null,
  13. "file_name": null,
  14. "file_type": "json",
  15. "job_id": "RcnyXjPH8zLSsUYrIlPsG5qnBERYFrGF",
  16. "operation": "export",
  17. "status": "pending",
  18. "updated_at": 1574405175
  19. }
  20. ]
  21. }

状态码说明

200: 成功

数据导入

接口

POST https://cloud.minapp.com/oserve/v1/table/:table_id/import/

提交参数

Content-Type: multipart/form-data

参数类型必填说明
fileStringY上传的文件流

支持 csv、json 文件导入,格式请于帮助中心查看

代码示例

  1. curl -X POST \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: multipart/form-data" \
  4. -F file=@"filename" \
  5. https://cloud.minapp.com/oserve/v1/table/:table_id/import/
  1. var request = require('request');
  2. var fs = require('fs');
  3. var opt = {
  4. uri: 'https://cloud.minapp.com/oserve/v1/table/:table_id/import/',
  5. method: 'POST',
  6. headers: {
  7. Authorization: `Bearer ${token}`
  8. },
  9. formData: { // 指定 data 以 "Content-Type": "multipart/form-data" 传送
  10. file: fs.createReadStream(__dirname + '/test.csv') // 参数需为文件流
  11. }
  12. }
  13. request(opt, function(err, res, body) {
  14. console.log(res.statusCode, body)
  15. })
  1. <?php
  2. $table_id = 1; // 数据表的 ID
  3. $url = "https://cloud.minapp.com/oserve/v1/table/{$table_id}/import/";
  4. if (class_exists('CURLFile')) {
  5. $param = array(
  6. 'file' => new \CURLFile(realpath( __DIR__.'/demo.csv'), 'csv', 'demo.csv')
  7. );
  8. } else {
  9. $param = array(
  10. 'file'=>'@'.realpath( __DIR__.'/demo.csv')
  11. );
  12. }
  13. $ch = curl_init();
  14. $header = array(
  15. "Authorization: Bearer {$token}",
  16. 'Content-Type: multipart/form-data; charset=utf-8'
  17. );
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  19. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  20. curl_setopt($ch, CURLOPT_URL, $url);
  21. curl_setopt($ch, CURLOPT_POST, true);
  22. curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
  23. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  24. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  25. $res['response'] = curl_exec($ch); // 反馈结果
  26. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  27. curl_close($ch);

返回示例

  1. {
  2. "status": "ok"
  3. }

状态码说明

201: 导入任务创建成功

400: 无效的文件