跳转到主要内容
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>"
}
'
import requests

url = "https://api.mintlify.com/v1/project/preview/{projectId}"

payload = { "branch": "<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>'})
};

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>'
  ]),
  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}")

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

response = http.request(request)
puts response.read_body
{
  "statusId": "<string>",
  "previewUrl": "<string>"
}
{
  "error": "<string>"
}
{
  "error": "<string>"
}
使用此端点以编程方式为 Git 分支创建或更新预览部署。如果指定分支已存在预览,该端点将触发重新部署,而不会创建重复项。 响应中包含一个 statusId,你可以将其传递给 Get deployment status 以跟踪部署进度。

用例

  • CI/CD 流水线:在拉取请求被打开或更新时自动创建预览部署。
  • 定时预览:按计划为长期运行的功能分支生成预览。
  • 自定义工具:将预览创建集成到内部工作流或 Slack 机器人中。

速率限制

此端点允许每个组织每分钟最多 5 个请求。

授权

Authorization
string
header
必填

Authorization 请求头需要使用 Bearer token。请使用以 mint_ 为前缀的管理员 API key。该 key 是仅供服务端使用的机密密钥。你可以在控制台的 API keys 页面 中生成一个。

路径参数

projectId
string
必填

项目 ID。可在控制台的 API keys 页面中复制。

请求体

application/json
branch
string
必填

要为其创建预览部署的 Git 分支名称。

Minimum string length: 1

响应

预览部署已成功加入队列。

statusId
string

用于跟踪预览部署的状态 ID。可将其与 Get deployment status 端点配合使用。

previewUrl
string

预览部署所托管的 URL。