Webhooks
配置 Webhook
设置您的 Webhook URL
POST
/
api
/
v1
/
webhooks
/
configure
配置 Webhook
curl --request POST \
--url https://api.example.com/api/v1/webhooks/configure \
--header 'Content-Type: application/json' \
--data '
{
"url": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/webhooks/configure"
payload = { "url": "<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({url: '<string>'})
};
fetch('https://api.example.com/api/v1/webhooks/configure', 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/api/v1/webhooks/configure",
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([
'url' => '<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;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/webhooks/configure"
payload := strings.NewReader("{\n \"url\": \"<string>\"\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.example.com/api/v1/webhooks/configure")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/webhooks/configure")
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 \"url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"webhook_url": "<string>",
"webhook_secret": "<string>"
}配置 Webhook
设置账户的 Webhook URL。每个账户一个 URL,两种事件都发送到该地址。API 密钥无法调用此接口。 修改 Webhook URL——以及读取签名密钥——都需要您本人在网站上开启的会话。使用 API 密钥时请求会被拒绝:否则,一把被盗的密钥就足以把您的事件指向他人的服务器。请在 Dashboard → API 中设置 URL;同一页面也会显示签名密钥。
Response
{
"detail": {
"error": {
"code": "FORBIDDEN_SESSION_TYPE",
"message": "This action is not available for this session type"
}
}
}
请求体
string
必填
Webhook URL。此接口仅接受 HTTPS,且不得指向
localhost、127.0.0.1、0.0.0.0 或 ::1。此外,发送时若主机解析到私有、回环或链路本地地址,投递同样会被拒绝。响应
string
当前配置的 URL。
string
用于
X-Webhook-Signature 的签名密钥。在账户首次设置 URL 时生成,之后保持不变。Response
{
"webhook_url": "https://yourserver.com/webhook/tronrental",
"webhook_secret": "3f2a9c...64 hex characters..."
}
后台入口
后台使用另一对接口操作同样的账户级字段——GET /api/v1/account/webhook 读取 URL 和密钥,PATCH /api/v1/account/webhook 设置或清除。两者接受相同的值,但有两点不同:PATCH 还允许 http:// 地址,发送 {"webhook_url": null} 可清除 Webhook。
清除 URL 会保留密钥,因此日后重新启用 Webhook 不会使您已部署的校验代码失效。
这两个接口同样需要网站会话。⌘I
配置 Webhook
curl --request POST \
--url https://api.example.com/api/v1/webhooks/configure \
--header 'Content-Type: application/json' \
--data '
{
"url": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/webhooks/configure"
payload = { "url": "<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({url: '<string>'})
};
fetch('https://api.example.com/api/v1/webhooks/configure', 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/api/v1/webhooks/configure",
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([
'url' => '<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;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/webhooks/configure"
payload := strings.NewReader("{\n \"url\": \"<string>\"\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.example.com/api/v1/webhooks/configure")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/webhooks/configure")
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 \"url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"webhook_url": "<string>",
"webhook_secret": "<string>"
}