{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-apis.sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"API Tokens in WHM","description":"With its world-class support and rich feature set, cPanel &amp; WHM has been the industry-leading web hosting platform for over 20 years. Trusted worldwide by our technology partners WordPress, CloudLinux, LiteSpeed, and more.","siteUrl":"https://api.docs.cpanel.net/","image":"/assets/cpanel-whm.ccd85fdccb18de0645f8a6ebf38e36a0489b92fc9d4ca92776f06aa5a160b167.db81178d.svg","keywords":"documentation, api, portal, cpanel","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"api-tokens-in-whm","__idx":0},"children":["API Tokens in WHM"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"overview","__idx":1},"children":["Overview"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["API tokens allow you to call WHM API 1 functions outside of a WHM session. You can use API tokens instead of a password to call WHM API 1 functions over ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HTTPS"]},". This is useful, for example, to allow a reseller user or third-party developer to run API function calls with your account's data."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Important:"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["API calls using a method that includes a URL must use one the following ports:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["2087"]}," - Secure calls to WHM's APIs, or to cPanel's APIs via the WHM API 1."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["443"]}," - Secure calls to WHM's APIs, or to cPanel's APIs via the WHM API 1 through a ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://go.cpanel.net/ServiceProxySubdomains"},"children":["service subdomain"]},"."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"creating-an-api-token","__idx":2},"children":["Creating an API token"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To create an API token, use WHM's ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://go.cpanel.net/whmdocsManageasisAPITokens"},"children":[{"$$mdtype":"Tag","name":"em","attributes":{},"children":["Manage API Tokens"]}]}," interface (",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["WHM >> Home >> Development >> Manage API Tokens"]},"). You can also use the WHM API 1 ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/openapi/whm/operation/api_token_create/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["api_token_create"]}]}," function."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Note:"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["In cPanel & WHM version 82, when an API token expires, the system will ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["not"]}," remove it. You must manually delete an API token."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["You can remove an API token with WHM's ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://go.cpanel.net/whmdocsManageasisAPITokens"},"children":[{"$$mdtype":"Tag","name":"em","attributes":{},"children":["Manage API Tokens"]}]}," interface (",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["WHM >> Home >> Development >> Manage API Tokens"]},") or the WHM API 1 ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/openapi/whm/operation/api_token_revoke/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["api_token_revoke"]}]}," function."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Warning:"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Make ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["certain"]}," that you save your API token in a secure location on your workstation. You ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["cannot"]}," access the token after navigating away from the interface or refreshing the API Tokens table."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"using-an-api-token","__idx":3},"children":["Using an API token"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To call a WHM API 1 function with an API token, ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/whm/introduction"},"children":["call it via HTTPS"]}," and include the following HTTP header in your request:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"Authorization: whm username:token\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Note:"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In this example, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["username"]}," represents the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["root"]}," user or a reseller user and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["token"]}," represents the API token."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-scripts","__idx":4},"children":["Example scripts"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use the following examples to create a script that includes the API token in your custom code:"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"perl","__idx":5},"children":["Perl"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Note:"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Specify either the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["root"]}," user or a reseller user in line 9."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["MYAPITOKEN"]}," in line 10 with your valid API token."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["127.0.0.1"]}," in line 18 with your server's IP address."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse JSON       ();\nuse HTTP::Tiny ();\n\n\nmy $user  = 'root';\nmy $token = 'MYAPITOKEN';\nmy $ua = HTTP::Tiny->new(\n    'verify_SSL'      => 0,\n    'default_headers' => {\n        'Authorization' => \"whm $user:$token\",\n    },\n);\n\nmy $response = $ua->get(\"https://127.0.0.1:2087/json-api/listaccts?api.version=1\");\nif ( $response->{'success'} ) {\n    my $json = JSON::decode_json( $response->{'content'} );\n    print \"[+] Current cPanel users on the system:\\n\";\n    print \"\\t$_\\n\" for map { $_->{'user'} } @{ $json->{'data'}->{'acct'} };\n}\nelse {\n    print \"[!] Error: $response->{'status'} $response->{'reason'} returned\\n\";\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["In line 10, the script declares the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["$token"]}," variable and assigns the API token hash to it as a value."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["In line 11, the script creates an ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HTTP::Tiny"]}," user agent. It also configures it to send the token authorization headers with every request."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Line 18 invokes the WHM API 1 ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/openapi/whm/operation/listaccts/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["listaccts"]}]}," function via the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HTTP::Tiny"]}," user agent and saves the response in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["$response"]}," variable."," ","The script prints the following output:",{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["listacct"]}," function succeeds, it parses the JSON data and returns the account's usernames."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["listacct"]}," function fails, it returns an error message."]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"php","__idx":6},"children":["PHP"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Notes:"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Specify either the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["root"]}," user or a reseller user in line 2."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["MYAPITOKEN"]}," in line 3 with your valid API token."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["127.0.0.1"]}," in line 5 with your server's IP address."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"<?\n    $user = \"root\";\n    $token = \"MYAPITOKEN\";\n\n    $query = \"https://127.0.0.1:2087/json-api/listaccts?api.version=1\";\n\n    $curl = curl_init();\n    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);\n    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);\n    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);\n\n    $header[0] = \"Authorization: whm $user:$token\";\n    curl_setopt($curl,CURLOPT_HTTPHEADER,$header);\n    curl_setopt($curl, CURLOPT_URL, $query);\n\n    $result = curl_exec($curl);\n\n    $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n    if ($http_status != 200) {\n        echo \"[!] Error: \" . $http_status . \" returned\\n\";\n    } else {\n        $json = json_decode($result);\n        echo \"[+] Current cPanel users on the system:\\n\";\n        foreach ($json->{'data'}->{'acct'} as $userdetails) {\n            echo \"\\t\" . $userdetails->{'user'} . \"\\n\";\n        }\n    }\n\n    curl_close($curl);\n?>\n"},"children":[]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Line 2 sets the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["$user"]}," value as the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["root"]}," user."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Line 3 sets the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["$token"]}," value as the contents of the appropriate API token."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Line 5 initializes the WHM API 1 ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/openapi/whm/operation/listaccts/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["listaccts"]}]}," function via a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["curl"]}," call. It then configures the call to send the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Authorization: token $user:$token"]}," headers with every request."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Line 16 performs the WHM API 1 ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/openapi/whm/operation/listaccts/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["listaccts"]}]}," function via a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["curl"]}," call and saves the response in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["$response"]}," variable."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["The script prints the following output:",{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/openapi/whm/operation/listaccts/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["listaccts"]}]}," function succeeds, it parses the JSON data and returns the account's usernames."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/openapi/whm/operation/listaccts/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["listaccts"]}]}," function fails, it returns an error message."]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"curl","__idx":7},"children":["curl"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Note:"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Specify either the root user or a reseller user for the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["username"]}," entry."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["MYAPITOKEN"]}," with your valid API token."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["127.0.0.1"]}," with your server's IP address."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"curl -H'Authorization: whm username:MYAPITOKEN' 'https://127.0.0.1:2087/json-api/applist?api.version=1'\n"},"children":[]}]},"headings":[{"value":"API Tokens in WHM","id":"api-tokens-in-whm","depth":1},{"value":"Overview","id":"overview","depth":2},{"value":"Creating an API token","id":"creating-an-api-token","depth":2},{"value":"Using an API token","id":"using-an-api-token","depth":2},{"value":"Example scripts","id":"example-scripts","depth":3},{"value":"Perl","id":"perl","depth":4},{"value":"PHP","id":"php","depth":4},{"value":"curl","id":"curl","depth":4}],"frontmatter":{"seo":{"title":"API Tokens in WHM"}},"lastModified":"2026-11-03T20:46:36.147Z","pagePropGetterError":{"message":"","name":""}},"slug":"/whm/tokens","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}