How to Create Packets
Assume that you need to create a customer account and remove accounts with IDs 1324 and 1325. Also assume that you know the Plesk version, say, it is Plesk 10.4. Then according to the protocol-product table, the best choice is to use XML API 18.104.22.168 since Plesk 10.4 ships with this protocol version.
Start with adding the packet node and defining the protocol version. You should have a similar packet:
<?xml version="1.0" encoding="UTF-8" ?> <packet> </packet>
Then open the reference part of the document, find the section about operations on customer accounts - Managing Customer Accounts, and construct the packet you need using the notation, descriptions, and samples.
To learn how to read graphical notations corresponding to operations, see Before Using the Reference.
According to the example, a packet will be extended to:
<?xml version="1.0" encoding="UTF-8" ?> <packet> <customer> <add> <gen_info> <cname>LogicSoft Ltd.</cname> <pname>Stephen Lowell</pname> <login>stevelow</login> <passwd>Jhtr66fBB</passwd> <status>0</status> <phone>416 907 9944</phone> <fax>928 752 3905</fax> <email>firstname.lastname@example.org</email> <address>105 Brisbane Road, Unit 2</address> <city>Toronto</city> <state/> <pcode/> <country>CA</country> </gen_info> </add> <del> <filter> <id>1324</id> <id>1325</id> </filter> </del> </customer> </packet>
Here, the requested operations (add and del) are nested within the customer operator element. XML API supports requests for operations on multiple Plesk objects. This request packet is also valid:
<?xml version="1.0" encoding="UTF-8" ?> <packet> <customer> <add> ... </add> </customer> <site> <add> ... </add> </site> ... </packet>
The operations are performed sequentially. Each group of operations is isolated within the relevant operator so that operations with similar names requested for different Plesk objects would never conflict.
For details on how to execute the operation described by a packet by programming means, see Creating Client Software.
Note: The order of nodes and elements within operations in your request packet is important. In most cases, the order must be the same as in the corresponding schema (or graphical notation).
For example, when creating mail accounts, you use the following packet structure:
According to the packet structure, the right order of elements within the mailname node is:
<packet> <mail> <create> <filter> <site-id>8</site-id> <mailname> <name>user</name> <password> <value>testpass</value> <type>plain</type> </password> <antivir>inout</antivir> </mailname> </filter> </create> </mail> </packet>
And the wrong order is:
<packet> <mail> <create> <filter> <site-id>8</site-id> <mailname> <name>user</name> <antivir>inout</antivir> <password> <value>testpass</value> <type>plain</type> </password> </mailname> </filter> </create> </mail> </packet>