• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    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. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Resolved Problems with an Excel VBA script using XML API

Peter_S

New Pleskian
Server operating system version
?
Plesk version and microupdate number
?
Hello,

I am new here and am trying to create an Excel VBA script to create a new customer account via XML API.

The script looks like this:

Code:
Option Explicit

Sub PleskApiXMLRequest()
    Dim sPleskHost As String
    Dim sPleskLogin As String
    Dim sPleskPassword As String
    Dim sRequest As String
  
    ' Set the Plesk server URL, login and password
    sPleskHost = "https://xyz.com:8443"
    sPleskLogin = "..."
    sPleskPassword = "..."
  
    ' Create a WinHttpRequest object
    Dim oHttpRequest As New WinHttp.WinHttpRequest
  
    ' Open an HTTP connection to the Plesk server
    oHttpRequest.Open "POST", sPleskHost & "/enterprise/control/agent.php HTTP/1.1", False
  
    ' Set the HTTP headers
    oHttpRequest.SetCredentials sPleskLogin, sPleskPassword, 0
    oHttpRequest.setRequestHeader "Content-type", "text/xml"
  
    ' Set the XML code for the API request
    Dim sPname As String
    Dim sLogin As String
    Dim sPasswd As String
    Dim sPlanName As String
    sPname = "Fritz Mustermann
    sLogin = "fritz"
    sPasswd = "secret"
    sPlanName = "Basis"

    sRequest = "<packet><reseller><add><gen_info><pname>" & sPname & "</pname><login>" & sLogin & "</login><passwd>" & sPasswd & "</passwd></gen_info><limits><limit-name>max_subdomains</limit-name><value>10</value></limits><permissions><permission-name>manage_phosting</permission-name><value>true</value></permissions><pool/><plan-name>" & sPlanName & "</plan-name></add></reseller></packet>"
  
    ' Send the API request
    oHttpRequest.send sRequest
  
    ' Get the API response
    Dim sResponse As String
    sResponse = oHttpRequest.responseText
  
    ' Print the API response in a message box
    MsgBox sResponse

End Sub

As a result, I receive the following response:

Code:
-- Copyright 1999-2023. Plesk International GmbH. All rights reserved. --
html lang="en" dir="ltr"
head
    meta charset="utf-8"
    meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"
    title 404 Page Not Found /title
    link rel="shortcut icon" href="/favicon.ico"
    link rel="stylesheet" href="/ui-library/plesk-ui-library.css?3.31.0"
    script src="/ui-library/plesk-ui-library.min.js?3.31.0" /script
    script src="/cp/javascript/vendors.js" /script
    script src="/cp/javascript/main.js"> /script
    script src="/error_docs/uat.js?v3" /script
link href="/error_docs/app.css?5ddcce66fe3b3bc08d68" rel="stylesheet"
/head
body
div id="app" /div
script window.__INITIAL_DATA__ = {"code":"404","message":"Page Not Found"} /script
script src="/error_docs/app.js?5ddcce66fe3b3bc08d68" /script
/body

What am I doing wrong?

The request "<packet><server><get_protos/></server></packet>" brings the same result.

Best regards
Peter
 
Based on the response I suspect there might be something wrong with the URL you're using. Because any proper API response should be XML formatted.

If you haven't already, try using API browser application, like Postman, for testing your API calls first. That way you can easily see if the API calls work as intended or if they are erroneous. Which also helps to (better) determine if there is something wrong with your script.
 
Also, are you sure having HTTP/1.1 in the same string as the URL is correct?

Code:
oHttpRequest.Open "POST", sPleskHost & "/enterprise/control/agent.php HTTP/1.1", False
 
Hello Kaspar,

thanks a lot for your reply.

I found another script for Excel VBA which works fine now.

Best regards
Peter
 
Back
Top