批量授权
curl --request POST \
--url https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants \
--header 'Content-Type: application/json' \
--data '
{
"app_names": [
"<string>"
],
"usernames": [
"<string>"
]
}
'import requests
url = "https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants"
payload = {
"app_names": ["<string>"],
"usernames": ["<string>"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({app_names: ['<string>'], usernames: ['<string>']})
};
fetch('https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({app_names: ['<string>'], usernames: ['<string>']})
};
fetch('https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants', 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/data-apps/batch/grants"
payload := strings.NewReader("{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", 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.post("https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants")
.header("Content-Type", "application/json")
.body("{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'app_names' => [
'<string>'
],
'usernames' => [
'<string>'
]
]),
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/data-apps/batch/grants")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_bodyusing RestSharp;
var options = new RestClientOptions("https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
val client = OkHttpClient()
val mediaType = MediaType.parse("application/json")
val body = RequestBody.create(mediaType, "{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}")
val request = Request.Builder()
.url("https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants")
.post(body)
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()false{
"granted": 123,
"requested": 123,
"apps": [
{
"app_name": "<string>",
"ok": true,
"code": "<string>"
}
],
"users": [
{
"username": "<string>",
"ok": true,
"code": "<string>"
}
]
}发布与运营
批量授权
一次把多个 App 分享给多个用户,矩阵语义,幂等。
POST
/
v1
/
data-apps
/
batch
/
grants
批量授权
curl --request POST \
--url https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants \
--header 'Content-Type: application/json' \
--data '
{
"app_names": [
"<string>"
],
"usernames": [
"<string>"
]
}
'import requests
url = "https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants"
payload = {
"app_names": ["<string>"],
"usernames": ["<string>"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({app_names: ['<string>'], usernames: ['<string>']})
};
fetch('https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({app_names: ['<string>'], usernames: ['<string>']})
};
fetch('https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants', 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/data-apps/batch/grants"
payload := strings.NewReader("{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", 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.post("https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants")
.header("Content-Type", "application/json")
.body("{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'app_names' => [
'<string>'
],
'usernames' => [
'<string>'
]
]),
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/data-apps/batch/grants")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_bodyusing RestSharp;
var options = new RestClientOptions("https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
val client = OkHttpClient()
val mediaType = MediaType.parse("application/json")
val body = RequestBody.create(mediaType, "{\n \"app_names\": [\n \"<string>\"\n ],\n \"usernames\": [\n \"<string>\"\n ]\n}")
val request = Request.Builder()
.url("https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants")
.post(body)
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()false{
"granted": 123,
"requested": 123,
"apps": [
{
"app_name": "<string>",
"ok": true,
"code": "<string>"
}
],
"users": [
{
"username": "<string>",
"ok": true,
"code": "<string>"
}
]
}端点
POST https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants
Authorization: Bearer <API Key>)。
一次向多个用户开放多个你拥有的 App(矩阵语义,幂等)。存储与生效规则与单用户授权相同。每个用户名只解析一次。granted 只计新增的配对,已在名单上的配对幂等跳过,便于区分「新增 3 个、已有 2 个」。
请求
请求体
string[]
必填
—
string[]
必填
用户名列表。
示例请求
curl -X POST \
-H "Authorization: Bearer $BAZHUAYU_API_KEY" \
-H "Content-Type: application/json" \
-d '{"apps": ["carol/reviews-query", "carol/product-detail"], "usernames": ["dave", "erin"]}' \
"https://api-datahub.bazhuayu.com/v1/data-apps/batch/grants"
响应
200 成功
{
"data": {
"granted": 3,
"skipped": 1,
"apps": [
{
"app": "carol/reviews-query",
"ok": true
},
{
"app": "carol/product-detail",
"ok": true
}
],
"users": [
{
"username": "dave",
"ok": true
},
{
"username": "erin",
"ok": true
}
]
}
}
data 字段中,其内容如下。
integer
必填
新增的授权配对数。
integer
必填
—
错误
| HTTP | code | category | 说明 |
|---|---|---|---|
| 401 | unauthorized | forbidden | 缺少或无效的 API Key。 |
{"error": {code, category, message, retryable}},见错误。
