plesk/api-php-lib

Multiple Site Alias request returns insufficient error content

ivjames opened this issue · 4 comments

In setting up some tools to 'bulk-manage' site aliases, it appears that when I make a request to get Info for multiple Site Aliases and one of them doesn't exist, I get a generic, singular, and somewhat malformed result. Examples below:

There were four aliased subdomains on qa.domain.com. The last two aliases have been removed prior to this test.

REQUEST

<packet>
    <site-alias>
        <get>
            <filter>
                <name>alias-02.qa.domain.com</name>
                <name>alias-03.qa.domain.com</name>
                <name>alias-04.qa.domain.com</name>
                <name>alias-05.qa.domain.com</name>
            </filter>
        </get>
    </site-alias>
</packet>

RESPONSE (in JSON for readability)

{
    "success": false,
    "domain": "..domain.com",
    "message": "Domain alias does not exist"
}

The domain element is malformed, and it neither gives me the info that it can get on the existing aliases, nor does it tell me which aliases, if any, do not exist.

I can work around this by making discrete calls to see which fail, but cringe at the wasted overhead and time to set this up.

The addition made in #72 may give a better workaround than using a raw packet-based request, but it still seems like this should work better than it does. I'll see if I can find time to locate where this is happening in the code, but if anyone can point me in the right direction, I don't mind rolling up the proverbial sleeves and taking a whack at it.

Seeing a similar result in bulk deletion as well; if I request for four aliases to be deleted and one does not exist, I get the same result packet with the "success": false. It does delete the three domains that do exist, it just indicates otherwise. Seems like the bulk responses are being broken when not all of the aliases exist.

Also, I just realized that I don't know if this is happening in this lib's handling of the API or if it's in the API itself.

Plesk API works well for such a case:

<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.9.1">
  <site-alias>
    <get>
      <result>
        <status>ok</status>
        <filter-id>alias-02.qa.domain.com</filter-id>
        <id>1</id>
        <info>
          <status>0</status>
          <pref>
            <web>true</web>
            <mail>true</mail>
            <seo-redirect>true</seo-redirect>
          </pref>
          <manage-dns>true</manage-dns>
          <site-id>5</site-id>
          <name>alias-02.qa.domain.com</name>
          <ascii-name>alias-02.qa.domain.com</ascii-name>
        </info>
      </result>
      <result>
        <status>ok</status>
        <filter-id>alias-03.qa.domain.com</filter-id>
        <id>2</id>
        <info>
          <status>0</status>
          <pref>
            <web>true</web>
            <mail>true</mail>
            <seo-redirect>true</seo-redirect>
          </pref>
          <manage-dns>true</manage-dns>
          <site-id>5</site-id>
          <name>alias-03.qa.domain.com</name>
          <ascii-name>alias-03.qa.domain.com</ascii-name>
        </info>
      </result>
      <result>
        <status>error</status>
        <errcode>1013</errcode>
        <errtext>Domain alias does not exist</errtext>
        <filter-id>alias-04.qa.domain.com</filter-id>
      </result>
      <result>
        <status>error</status>
        <errcode>1013</errcode>
        <errtext>Domain alias does not exist</errtext>
        <filter-id>alias-05.qa.domain.com</filter-id>
      </result>
    </get>
  </site-alias>
</packet>

PHP library has no special method for bulk "get" of site aliases. So please provide here a PHP code snippet instead of an XML request. There are so many ways to do it.