• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

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