• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • Support for BIND DNS has been removed from Plesk for Windows due to security and maintenance risks.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS.

Question problem with plesk rest-api

millerbln

New Pleskian
Server operating system version
Ubuntu 24.04 x86_64
Plesk version and microupdate number
Plesk Obsidian 18.0.70.1
hello,
i have problems to get the traffic with rest-api ;-(

this and other commands working very well:
Code:
curl -X GET -H "X-API-Key: 12345678-1234-5678-1234-123456789012" -H "Content-Type: application/json" -H "Accept: application/json" "https://xx-yy.de:8443/api/v2/server"
i get all Infos About the server.

but this command not working, i have try with several changes,
Nothing helps ;-(

Code:
curl -X POST -H "X-API-Key: 12345678-1234-5678-1234-123456789012" -H "Content-Type: application/json" -H "Accept: application/json" -d @/root/pleskapi/plesk-traffic1.json "https://xx-xx.de:8443/api/v2/cli/webspace/get_traffic"

Code:
my plesk-traffic1.json is this:
{
<packet>
    <webspace>
      <get_traffic>
         <filter-id>5</filter-id>     
           <since_date>2025-03-01</since_date>
       </get_traffic>
    </webspace>
  </packet>
 }

can anybody help me please ??

thanks & regards
millerbln

 
No need to write your whole post in large and bold text. It doesn't make it any more readable for others (on the contrary).

Anyway, /api/v2/cli/webspace/get_traffic is not a valid end point for the REST API. You've seem to have mixed up the REST API and XML API, which won't work (as you've noticed). You can call the /api/v2/cli/commands end point to see which exact CLI command are available for the REST API.

For example to get the traffic for a particular domain you can use the /api/v2/cli/domain/call end-point, which runs the CLI command (plesk bin domain example.com --info) to fetch all kinds of information domain from that particular domain. Including traffic usage. Have a look at the REST API playround in Plesk for example on how to use the CLI parameters on the REST API.

Alternatively you can use the XML API instead to get traffic usage on a domain, for which you can look at the documentation for more details.

Hope this helps.
 
Last edited:
i write large and bold not for others, i do i for me, that i can see, what i write.
i am an old man, my eyes have the same age like me.

i wrote now:
/api/v2/cli/domain/call mydomain.xx -info"
and
/api/v2/cli/domain/call/mydomain.xx -info"

result:
URL rejected: Malformed input to a URL function
:-(

when i look at the "agent_input.svg" , than i see, my "plesk-traffic1.json" is not for the rest api.

but how can i give in XML API to the "enterprise/control/agent.php" this, what i want ?
agent.php?x1=5&x2=3 ????

but always thanks for try to help me, kaspar
 
You'll need to provide the required parameters in the body of the API call. For example with the REST API you can do:
Code:
curl -X POST \
'https://xx-xx.de:8443/api/v2/cli/domain/call' \
-H 'X-API-Key: 12345678-1234-5678-1234-123456789012' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'  \
-d '{"params": [ "--info", "example.com"]}'
This uses the -d (--data) flag to send the required parameters for the call in the JSON format {"params": [ "--info", "example.com"]}.

You'll find more information and example's in the REST API playground. When you're logged in to Plesk go to Tools & Settings > Remote API (REST) > Plesk REST API.

For the XML API you'll need send the XML payload into the body. For example
Code:
curl -X POST \
'https://xx-xx.de:8443/enterprise/control/agent.php' \
-H 'KEY:12345678-1234-5678-1234-123456789012' \
-H 'Content-Type: text/xml' \
-H 'Accept: text/xml' \
-d '<packet><webspace><get_traffic><filter><name>example.com</name></filter><since_date>2025-01-01</since_date></get_traffic></webspace></packet>'
More information about making calls with the XMP API can be read in the XML API documentation.

i write large and bold not for others, i do i for me, that i can see, what i write.
i am an old man, my eyes have the same age like me.
I understand, my eyesight has diminished too as I get older (and spend too much time behind a computer screen). Perhaps it helps to configure your display scale or use the browser zoom feature. Here is a related video that explains the display scale option (on Windows 10 and 11) that might be helpful.
 
Last edited:
hello kaspar,
thank you again for trying to help me.

i have generated 84 help files for all 84 rest api commands.
i not find anything for "used traffic" like "since_date" or "to_date" in this 84 help files.
fact is , this only exist in XML api ;-(



curl -X POST \
'https://xx-xx.de:8443/api/v2/cli/domain/call' \
-H 'KEY:12345678-1234-5678-1234-123456789012' \
-H 'Content-Type: text/xml' \
-H 'Accept: text/xml' \
-d '<packet><webspace><get_traffic><filter><name>example.com</name></filter><since_date>2025-01-01</since_date></get_traffic></webspace></packet>'

the code snippet what you post , is not working.
i get no error, but also no response ;-(

may be, the beginning (curl -X POST .... ) is only for REST api and not for XML api ??
regards
millerbln
 
i have generated 84 help files for all 84 rest api commands.
i not find anything for "used traffic" like "since_date" or "to_date" in this 84 help files.

Please have a careful look at the output of the /cli/domain/call end-point call again. This should output the traffic usage, among other informatie about the domain. The REST API call should output something like this:
JSON:
{
  "code": 0,
  "stdout": "General\n=============================\nDomain ID:                              5\nDomain name:                            example.com\nOwner's contact name:                   kaspar (kaspar)\nDomain status:                          OK\nCreation date:                          May 15, 2025\nExpiration date:                        Unlimited\nDisk space limit:                       100 MB\nSize:                                   6.69 MB\nTotal size of backup files in local storage:0 B\nTraffic limit:                          100 MB\nTraffic:                                9.7 MB/Month\nDescription:                            \nDescription for the administrator:      \nExternal ID:                            \n\nHosting\n=============================\nHosting type:                           Physical hosting\nIP Address:                             123.123.123.123\nFTP Login:                               example.com_4227oa1\nFTP Password:                           ************\nSSH access to the server shell under the subscription's system user:/bin/false\nHard disk quota:                        Unlimited (not supported)\nDisk space used by httpdocs:            108 KB\nDisk space used by Log files and statistical reports:6.47 MB\nCertificate:                            Lets Encrypt  example.com\nSSL/TLS support:                        On\nPermanent SEO-safe 301 redirect from HTTP to HTTPS:On\nSSI support:                            No\nPHP support:                            Yes\nCGI support:                            No\nPerl support:                           No\nPython support:                         No\nFastCGI support:                        Yes\nCustom error documents:                 Yes\nWeb statistics:                         Webalizer\nAnonymous FTP:                          No\nDisk space used by Anonymous FTP:       0 B\n\nWeb Users\n=============================\nTotal :                                 0\nSSI support:                            0\nPHP support:                            0\nCGI support:                            0\nPerl support:                           0\nPython support:                         0\nFastCGI support:                        0\nTotal size:                             0 B\n\nMail Accounts\n=============================\nMail service:                           On\nTotal :                                 2\nAccess to Plesk:                        0\nMailboxes:                              2\nMail forwardings:                       0\nAuto-replies:                           0\nTotal size:                             120 KB\nMail autodiscover:                      On\n\nMailing Lists\n=============================\nMailing list service:                   Off\nTotal :                                 0\nTotal size:                             0 B\n\nDatabases\n=============================\nTotal :                                 0\nTotal size:                             0 B\n\nWeb Applications\n=============================\nTotal :                                 0\n\n\nLogrotation info\n==============================\nLog rotation status:                    On\nLog rotation condition:                 10240KB (by size)\nMaximum number of log files:            10\nCompress log files:                     true\nSend processed log files to email:      \n\n\n--WWW-Root--: /var/www/vhosts/ example.com/httpdocs\n\n\nSubscription Information\n==============================\nThe domain is subscribed to the service plan \"Test Plan\" of Administrator.\nThe subscription is not locked for syncing.\n\n\nSUCCESS: Gathering information for ' example.com' completed.",
  "stderr": ""
}
Which contains the following line with the traffic usage of the domain:
Code:
Traffic:                                9.7 MB/Month\n

curl -X POST \
'https://xx-xx.de:8443/api/v2/cli/domain/call' \
-H 'KEY:12345678-1234-5678-1234-123456789012' \
-H 'Content-Type: text/xml' \
-H 'Accept: text/xml' \
-d '<packet><webspace><get_traffic><filter><name>example.com</name></filter><since_date>2025-01-01</since_date></get_traffic></webspace></packet>'

the code snippet what you post , is not working.
i get no error, but also no response ;-(
My mistake. I posted the wrong URL. Instead of :8443/api/v2/cli/domain/call the URL should be :8443/enterprise/control/agent.php for use with the XML API.
 
Back
Top