管理
触发预览部署
为特定分支创建或更新预览部署。如果该分支已有预览,则会触发重新部署。返回用于跟踪进度的状态 ID 和预览 URL。
使用管理员 API 密钥进行身份验证。
POST
/
project
/
preview
/
{projectId}
触发预览部署
curl --request POST \
--url https://api.mintlify.com/v1/project/preview/{projectId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"branch": "<string>",
"auth": {
"type": "password",
"password": "<string>"
}
}
'import requests
url = "https://api.mintlify.com/v1/project/preview/{projectId}"
payload = {
"branch": "<string>",
"auth": {
"type": "password",
"password": "<string>"
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({branch: '<string>', auth: {type: 'password', password: '<string>'}})
};
fetch('https://api.mintlify.com/v1/project/preview/{projectId}', 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.mintlify.com/v1/project/preview/{projectId}",
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([
'branch' => '<string>',
'auth' => [
'type' => 'password',
'password' => '<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.mintlify.com/v1/project/preview/{projectId}"
payload := strings.NewReader("{\n \"branch\": \"<string>\",\n \"auth\": {\n \"type\": \"password\",\n \"password\": \"<string>\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.mintlify.com/v1/project/preview/{projectId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"branch\": \"<string>\",\n \"auth\": {\n \"type\": \"password\",\n \"password\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mintlify.com/v1/project/preview/{projectId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"branch\": \"<string>\",\n \"auth\": {\n \"type\": \"password\",\n \"password\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"statusId": "<string>",
"previewUrl": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}使用此端点以编程方式为 Git 分支创建或更新预览部署。如果指定分支已存在预览,该端点将触发重新部署,而不会创建重复项。
响应中包含一个
默认情况下,通过此端点创建的预览可公开访问,除非你为预览启用了身份验证。请参阅限制预览部署的访问权限。
要限制对特定预览的访问,请在请求体中传入
设置
此端点允许每个组织每分钟最多 5 个请求。
statusId,你可以将其传递给 Get deployment status 以跟踪部署进度。
分支要求
branch 必须存在于与你的 Mintlify 项目连接的仓库中,并且你必须已安装 Mintlify GitHub 应用。此端点不支持 fork 上的分支。有关如何预览来自 fork 的更改,请参阅Fork 拉取请求。
用例
- CI/CD 流水线:在用户打开或更新拉取请求时自动创建预览部署。
- 定时预览:按计划为长期运行的功能分支生成预览。
- 自定义工具:将预览创建集成到内部工作流或 Slack 机器人中。
预览的访问权限
auth 对象。Mintlify 会在将部署加入队列之前,将访问设置应用于该预览。如果省略 auth,预览将保留其当前的访问设置。
{ "type": "password", "password": "..." }:任何拥有密码的人都可以查看该预览。密码长度必须至少为 8 个字符。设置密码会替换该预览上已有的任何密码。{ "type": "mintlify" }:只有已登录 Mintlify 的组织成员才能查看该预览。
curl --request POST \
--url https://api.mintlify.com/v1/project/preview/{projectId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"branch": "feature/new-guide",
"auth": { "type": "password", "password": "review-pass-123" }
}'
auth 需满足以下要求:
- 你的方案必须包含预览部署身份验证。否则,该端点返回
403。 - 你的站点必须已启用身份验证或预览身份验证。否则,该端点返回
409。 - 必须在预览本身上启用身份验证。否则,该端点返回
409。
速率限制
⌘I
触发预览部署
curl --request POST \
--url https://api.mintlify.com/v1/project/preview/{projectId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"branch": "<string>",
"auth": {
"type": "password",
"password": "<string>"
}
}
'import requests
url = "https://api.mintlify.com/v1/project/preview/{projectId}"
payload = {
"branch": "<string>",
"auth": {
"type": "password",
"password": "<string>"
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({branch: '<string>', auth: {type: 'password', password: '<string>'}})
};
fetch('https://api.mintlify.com/v1/project/preview/{projectId}', 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.mintlify.com/v1/project/preview/{projectId}",
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([
'branch' => '<string>',
'auth' => [
'type' => 'password',
'password' => '<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.mintlify.com/v1/project/preview/{projectId}"
payload := strings.NewReader("{\n \"branch\": \"<string>\",\n \"auth\": {\n \"type\": \"password\",\n \"password\": \"<string>\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.mintlify.com/v1/project/preview/{projectId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"branch\": \"<string>\",\n \"auth\": {\n \"type\": \"password\",\n \"password\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mintlify.com/v1/project/preview/{projectId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"branch\": \"<string>\",\n \"auth\": {\n \"type\": \"password\",\n \"password\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"statusId": "<string>",
"previewUrl": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}