You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WHM API删除停放域名遇权限拒绝问题求助

WHM API 删除停放域名权限问题排查与解决

问题描述

已成功实现WHM API添加域名功能,但使用PHP CURL调用删除接口时失败,返回权限不足错误。

调用代码

$api       = "https://" . whm_domain . ":2087/json-api/delete_domain?api.version=2";
$curl      = curl_init();
curl_setopt($curl, CURLOPT_URL, $api);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(
    [
        "domain" => $_POST["domain"]
    ]));
curl_setopt($curl, CURLOPT_HTTPHEADER, ["Authorization: whm " . whm_username . ":" . whm_token]);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
$response  = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($http_code !== 200 || !is_json($response))
{
    http_response_code(400);
    exit(json_encode(["status" => "error", "response" => $lang["response-error"]]));
}
else
{
    $response = json_decode($response, true);

    if (json_last_error() !== JSON_ERROR_NONE || ($response["metadata"]["result"] ?? 0) !== 1)
    {
        http_response_code(400);
        exit(json_encode(["status" => "error", "response" => json_encode($response)]));
    }
}

错误响应

{"status":"error","response":"{\"metadata\":{\"version\":1,\"result\":0,\"reason\":\"Permission denied: You do not have the required privileges to run “delete_domain”.\",\"command\":\"delete_domain\"}}"}

排查与解决方法

  • 确认API接口是否正确:如果要删除的是停放域名,应调用unpark_domain接口而非delete_domain。delete_domain用于删除主域名,权限要求远高于移除停放域名的操作。修改API端点为:
    $api = "https://" . whm_domain . ":2087/json-api/unpark_domain?api.version=2";
    
  • 检查WHM用户/API令牌权限:
    1. 登录WHM面板,进入Resellers > Edit Reseller Nameservers and Privileges,找到对应用户,确认开启了Park DNS权限(包含移除停放域名的权限)。
    2. 进入Development > Manage API Tokens,查看当前使用的令牌权限列表,确保包含unpark_domain(或delete_domain,如果确实需要删除主域名)的权限。
  • 验证域名类型:确认目标域名是停放域名,而非主域名或附加域名。不同类型域名的删除接口不同:
    • 主域名:delete_domain
    • 停放域名:unpark_domain
    • 附加域名:delete_addon_domain

内容的提问来源于stack exchange,提问作者Fitri Ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 06:46:29