设置保留标记
curl --request PUT \
--url https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention \
--header 'Content-Type: application/json' \
--data '
{
"retained": true
}
'import requests
url = "https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention"
payload = { "retained": True }
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({retained: true})
};
fetch('https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({retained: true})
};
fetch('https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention"
payload := strings.NewReader("{\n \"retained\": true\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention")
.header("Content-Type", "application/json")
.body("{\n \"retained\": true\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'retained' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"retained\": true\n}"
response = http.request(request)
puts response.read_bodyusing RestSharp;
var options = new RestClientOptions("https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n \"retained\": true\n}", false);
var response = await client.PutAsync(request);
Console.WriteLine("{0}", response.Content);
val client = OkHttpClient()
val mediaType = MediaType.parse("application/json")
val body = RequestBody.create(mediaType, "{\n \"retained\": true\n}")
val request = Request.Builder()
.url("https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention")
.put(body)
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()false{
"dataset_id": "<string>",
"retained": true
}数据集
设置保留标记
把数据集标记为长期保留,或取消标记。
PUT
/
v1
/
datasets
/
{dataset_id}
/
retention
设置保留标记
curl --request PUT \
--url https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention \
--header 'Content-Type: application/json' \
--data '
{
"retained": true
}
'import requests
url = "https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention"
payload = { "retained": True }
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({retained: true})
};
fetch('https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({retained: true})
};
fetch('https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention"
payload := strings.NewReader("{\n \"retained\": true\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention")
.header("Content-Type", "application/json")
.body("{\n \"retained\": true\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'retained' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"retained\": true\n}"
response = http.request(request)
puts response.read_bodyusing RestSharp;
var options = new RestClientOptions("https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n \"retained\": true\n}", false);
var response = await client.PutAsync(request);
Console.WriteLine("{0}", response.Content);
val client = OkHttpClient()
val mediaType = MediaType.parse("application/json")
val body = RequestBody.create(mediaType, "{\n \"retained\": true\n}")
val request = Request.Builder()
.url("https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention")
.put(body)
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()false{
"dataset_id": "<string>",
"retained": true
}端点
PUT https://api-datahub.bazhuayu.com/v1/datasets/{dataset_id}/retention
Authorization: Bearer <API Key>)。
运行结果默认自创建起保留 90 天;带保留标记的数据集不参与过期清理。标记是用户的明确声明:读取不会续期,设置与清除都是幂等的。
只能标记自己的数据集:别人的、平台公开的种子集和不存在的都返回 404。标记门比可见门窄,因为种子集不是你的产出,也不参与清理,标记它没有意义。
请求
路径参数
string
必填
数据集标识。
请求体
boolean
必填
true 标记保留,false 取消标记。示例请求
curl -X PUT \
-H "Authorization: Bearer $BAZHUAYU_API_KEY" \
-H "Content-Type: application/json" \
-d '{"retained": true}' \
"https://api-datahub.bazhuayu.com/v1/datasets/ds_0bd5345d13d0/retention"
响应
200 成功
{
"data": {
"dataset_id": "ds_0bd5345d13d0",
"retained": true
}
}
data 字段中,其内容如下。
string
必填
数据集标识。
boolean
必填
当前标记状态。
错误
| HTTP | code | category | 说明 |
|---|---|---|---|
| 401 | unauthorized | forbidden | 缺少或无效的 API Key。 |
| 404 | dataset-not-found | not_found | 数据集不存在、不属于当前账号,或是平台公共样例集(不可标记)。 |
{"error": {code, category, message, retryable}},见错误。
客户端库
client.set_dataset_retention("ds_0bd5345d13d0", retained=True)
await client.setDatasetRetention("ds_0bd5345d13d0", true);
