curl --request POST \
--url https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token \
--header 'x-user-id: <x-user-id>'import requests
url = "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token"
headers = {"x-user-id": "<x-user-id>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'x-user-id': '<x-user-id>'}};
fetch('https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"x-user-id: <x-user-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("x-user-id", "<x-user-id>")
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.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token")
.header("x-user-id", "<x-user-id>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-user-id"] = '<x-user-id>'
response = http.request(request)
puts response.read_body{
"token": "<string>",
"expires_at": 123
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Mint a short-lived token for a browser-native fetch
Mint a token so a browser can fetch the raw file directly.
<iframe> PDF previews, <img> tags and click-to-download
navigations carry no custom headers, so they cannot present
X-User-ID; the token rides in the URL instead and is bound to
exactly this document.
Args:
knowledge_base_id (str):
The parent knowledge base.
document_id (str):
The document the token authorizes.
user_id (str):
Injected authenticated user ID.
service (KnowledgeBaseService):
Injected knowledge base service — resolved here only to
fail early with a proper 404 instead of a raw error page
on the browser navigation.
download_secret (str):
Injected app-wide signing secret.
Returns:
DocumentDownloadTokenResponse:
The token and its expiry.
curl --request POST \
--url https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token \
--header 'x-user-id: <x-user-id>'import requests
url = "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token"
headers = {"x-user-id": "<x-user-id>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'x-user-id': '<x-user-id>'}};
fetch('https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"x-user-id: <x-user-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("x-user-id", "<x-user-id>")
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.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token")
.header("x-user-id", "<x-user-id>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/knowledge_bases/{knowledge_base_id}/documents/{document_id}/download_token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-user-id"] = '<x-user-id>'
response = http.request(request)
puts response.read_body{
"token": "<string>",
"expires_at": 123
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Headers
Caller's user ID. Temporary header-based identity; will be replaced by JWT auth.
Path Parameters
The knowledge base id.
The document id.
Response
Successful Response
A capability authorizing one fetch of one document's raw file.