The add-db operation is used to create a database for a certain subscription. You can specify the database settings only on creation. You can create a database of one of the following types:

  • MySQL or MS SQL in Plesk for Windows
  • MySQL or PostgreSQL in Plesk for Unix

Request Packet Structure

A request XML packet creating a database includes the add-db operation node:

<packet>
<database>
   <add-db>
   ...
   </add-db>
</database>
</packet>

The add-db node is presented by type DatabaseAddInputType (database_input.xsd), and its graphical representation is as follows:

image 37554

Note: The interactive schema navigator for all request packets is available here: http://plesk.github.io/api-schemas/1.6.8.0/agent_input.svg.

  • The webspace-id node is required. It specifies the subscription on which you want to create database. Data type: integer.
  • The name node is required. It specifies the database name. Data type: string.
  • The type node is required. It specifies the database type. MySQL and MS SQL are available in Plesk for Windows. MySQL and PostgreSQL types are available in Plesk for Unix. Data type: string.
  • The db-server-id node is optional. It specifies the ID of the database server on which the database will be created. If the node is not used, the default database server of the corresponding type will be used for the database creation. Data type: integer.

Note: Use lower case for the database types. In other case the request might be incorrectly processed by the server.

Remarks

You can add multiple databases in a single packet. Add as many add-db operations as the number of databases you want to add.

<database>
   <add-db>
   ...
   </add-db>
...
   <add-db>
   ...
   </add-db>

</database>

Note: When creating request packets, put nodes and elements in the order they follow in the packet structure.

Response Packet Structure

The add-db node of the output XML packet is presented by type DatabaseAddDBOutputType (database_output.xsd) and structured as follows:

image 37557

Note: The interactive schema navigator for all response packets is available here: http://plesk.github.io/api-schemas/1.6.8.0/agent_output.svg.

  • The result node is required. It wraps the response retrieved from the server. Data type: resultType (common.xsd).
  • The status node is required. It specifies the execution status of the add-db operation. Data type: string. Allowed values: ok | error.
  • The errcode node is optional. Is returns the error code if the add-db operation fails. Data type: integer.
  • The errtext node is optional. It returns the error message if the add-db operation fails. Data type: string.
  • The id node is optional. If the add-db operation succeeds, it returns the ID of the database. Data type: integer.

Samples

Adding a database

The request packet structured as follows:

<packet>
<database>

<add-db>
   <webspace-id>7</webspace-id>
   <name>MyBase</name>
   <type>mysql</type>
</add-db>

</database>
</packet>

 Request:

<packet>
<database>

<add-db>
   <result>
      <status>ok</status>
      <id>14</id>
   </result>
</add-db>

</database>
</packet>

If MyBase already exists, the response from the server looks as follows:

<packet>
<database>

<add-db>
<result>
      <status>error</status>
      <errcode>1007</errcode>
      <errtext>Database already exists</errtext>
</result>
</add-db>

</database>
</packet>

If the subscription with ID 7 was not found, the response looks as follows:

<packet>
<database>

<add-db>
<result>
      <status>error</status>
      <errcode>1015</errcode>
      <errtext>Domain does not exist</errtext>
</result>
</add-db>

</database>
</packet>

Adding multiple databases

The request packet adding mySQL and PostgreSQL databases looks as follows:

<packet>
<database>

<add-db>
   <webspace-id>3</webspace-id>
   <name>MyBase</name>
   <type>mysql</type>
</add-db>

<add-db>
   <webspace-id>3</webspace-id>
   <name>MyBase</name>
   <type>mysql</type>
</add-db>

</database>
</packet>

Response:

<packet>
<database>

<add-db>
<result>
      <status>ok</status>
      <id>14</id>
</result>
</add-db>

<add-db>
<result>
      <status>error</status>
      <errcode>1007</errcode>
      <errtext>Database already exists</errtext>
</result>
</add-db>

</database>
</packet>