数据导入导出操作

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

数据导出

接口

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

其中 table_id 是数据表的 ID

请求参数

参数 类型 必填 说明
file_type String 导出文件的格式,支持 csv、json 格式
mode String 导出任务的模式
start Integer 导出部分数据的起始时间(时间戳)
end Integer 导出部分数据的结束时间(时间戳)

导出任务支持两种模式:

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

info 选择部分数据导出任务时,将会根据数据的创建时间进行筛选,即 created_at 在 [start, end) 的区间内

代码示例

{% tabs exportCurl=”Curl”, exportNode=”Node”, exportPHP=”PHP” %}

{% content “exportCurl” %}

  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/table/:table_id/export/

{% content “exportNode” %}

  1. var request = require('request')
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/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. })

{% content “exportPHP” %}

  1. <?php
  2. $table_id = 1; // 数据表的 ID
  3. $url = "https://cloud.minapp.com/oserve/v1/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);

{% endtabs %}

返回示例

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

状态码说明

201: 导出任务创建成功

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

数据导入

接口

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

提交参数

Content-Type: multipart/form-data

参数 类型 必填 说明
file String Y 上传的文件流

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

代码示例

{% tabs importCurl=”Curl”, importNode=”Node”, importPHP=”PHP” %}

{% content “importCurl” %}

  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/

{% content “importNode” %}

  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. })

{% content “importPHP” %}

  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);

{% endtabs %}

返回示例

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

状态码说明

201: 导入任务创建成功

400: 无效的文件