> For the complete documentation index, see [llms.txt](https://www.docpartner.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.docpartner.dev/en/api/mail-partner/sub-accounts/create-sub-account.md).

# Create Sub-account

This request is used to create a sub-account.

## URL

<mark style="color:green;">`POST`</mark> `https://api.mailpartner.fr/v1/subaccount/create`

#### **Required Parameters**

<table data-full-width="false"><thead><tr><th width="180">Name</th><th>Value</th></tr></thead><tbody><tr><td><code>apiKey</code></td><td><a href="https://my.mailpartner.fr/dashboard/api">Your API key</a></td></tr><tr><td><code>type</code></td><td><p>Type of sub-account: this choice is final and cannot be modified later</p><ul><li>simple:<br>– The sub-account will not receive any email.<br>– No phone number is required.<br>– Purchases are not allowed.</li><li>advanced:<br>– A valid email is required.<br>– The registration process is the same as for a standard account.<br>– A mobile phone number will be required at signup.</li></ul></td></tr><tr><td><code>parameters</code></td><td><div data-gb-custom-block data-tag="tabs"><div data-gb-custom-block data-tag="tab" data-title="Simple sub-account"><ul><li><code>email</code> (optional): If this field is empty, an email will be generated automatically (e.g. 98755587@smspartner.fr)</li><li><code>creditToAttribute</code> (optional): Credit in euros added to the sub-account upon creation. This credit will be deducted from your main account's balance.</li><li><code>title</code> (optional): Name of the sub-account</li><li><code>firstname</code> (optional): First name of the sub-account holder</li><li><code>lastname</code> (optional): Last name of the sub-account holder</li></ul></div><div data-gb-custom-block data-tag="tab" data-title="Advanced sub-account"><ul><li><code>email</code>: Valid email of the account holder</li><li><code>isBuyer</code>: <code>1</code> or <code>0</code>, if isBuyer=1 the sub-account can purchase its own credits</li><li><code>creditToAttribute</code> (optional): Credit in euros added to the sub-account upon creation. This credit will be deducted from your main account's balance.</li><li><code>title</code> (optional): Name of the sub-account</li><li><code>firstname</code> (optional): First name of the sub-account holder</li><li><code>lastname</code> (optional): Last name of the sub-account holder</li></ul></div></div></td></tr></tbody></table>

#### Requests

{% tabs %}
{% tab title="PHP" %}

```php
<?php
        // Prepare data for POST request
        $fields = array(
            'apiKey'=> 'YOUR API KEY',
            'type'=> 'advanced',
            'parameters'=>array(
                'email':'aaaa@bbb.ccc',
    	        'creditToAttribute':10,
    	        'isBuyer':0,
    	        'firstname':'firstname',
    	        'lastname':'lastname'
            ));
 
 
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL,'https://api.mailpartner.fr/v1/subaccount/create');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($fields));
 
        $result = curl_exec($curl);
        curl_close($curl);
 
        // Process your response here
        echo $result;
?>
```

{% endtab %}

{% tab title="VB.net" %}

```vbnet
Imports System.IO
Imports System.Net
 
Module Module1
 
  Sub Main()
 
    Dim base_url As String = "http://api.mailpartner.fr/v1/"
    Dim apiKey As String = "YOUR_APIKEY"
 
    #create a sub-account
    url = base_url & "subaccount/create"
    #note: use a JSON library in production, for example:
    #https//www.nuget.org/packages/Newtonsoft.Json/
    Dim parameters As String = String.Format(
        "{{""apiKey"":""{0}"",""type"":""{1}"",""parameters"":""{2}""}}",
        apiKey,
        "advanced",
        {"email":"aaaa@bbb.ccc","creditToAttribute":10,"isBuyer":0,"firstname":"firstname","lastname":"lastname"})
    Console.Write(parameters)
    apiRequest("POST", url, parameters)
 
  End Sub
 
  Function apiRequest(method As String, url As String, parameters As String) As String
 
    Dim request As HttpWebRequest
    request = WebRequest.Create(url)
    request.Method = method
    request.Timeout = 10000   # timeout in ms
    request.ContentType = "application/json; charset=utf-8"
    request.ContentLength = 0
 
    #set POST data
    If Not String.IsNullOrEmpty(parameters) Then
      request.ContentLength = parameters.Length
      Using reqStream As StreamWriter = New StreamWriter(request.GetRequestStream())
        reqStream.Write(parameters)
      End Using
    End If
 
    #get response
    Dim returnValue As String = Nothing
    Using response As HttpWebResponse = request.GetResponse()
      If response.StatusCode = HttpStatusCode.OK Then
        Using resStream = response.GetResponseStream()
          If resStream IsNot Nothing Then
            Using reader As New StreamReader(resStream)
              returnValue = reader.ReadToEnd()
            End Using
          End If
        End Using
      End If
    End Using
    apiRequest = returnValue
 
  End Function
 
End Module
```

{% endtab %}

{% tab title="Python" %}

```python
# std
import logging
import json
from collections import OrderedDict
 
# 3p
import requests
 
API_KEY = "MY API KEY"
URL = "https://api.mailpartner.fr/v1"
 
class MailPartner():
    def create(self):
 
		data = {"apiKey":API_KEY,"type":"advanced","parameters": {"email":"aaaa@bbb.ccc","creditToAttribute":10,"isBuyer":0,"firstname":"firstname","lastname":"lastname"}}
 
 
		url = URL + "/subaccount/create"
		r = requests.post(url, data=json.dumps(data), verify=False)
 
		r_json = r.json()
		if r_json.get("success") == True:
			print(r_json)
			status = True
		else:
			print(r_json)
			status = False
		return status
```

{% endtab %}

{% tab title="cURL" %}

```
curl -H  "Content-Type: application/json" -X POST -d '{"apiKey":"xxxxx","type":"advanced","parameters":{"email":"aaaa@bbb.ccc","creditToAttribute":10,"isBuyer":0,"firstname":"firstname","lastname":"lastname"}}' https://api.mailpartner.fr/v1/subaccount/create
```

{% endtab %}
{% endtabs %}

#### **Response**

{% tabs %}
{% tab title="json" %}

```json
{
 "success":true,
 "code":200,
 "subaccount":
 {
    "email":"aaaa@bbb.ccc",
    "token":"token"
 },
 "sendConfirmMailTo":"aaaa@bbb.ccc",
 "parent_email":"emailparent@ddd.eee"
}
```

{% endtab %}

{% tab title="xml" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<result>
  <entry>true</entry>
  <entry>200</entry>
  <entry>
    <entry><![CDATA[aaaa@bbb.ccc]]></entry>
    <entry><![CDATA[token]]></entry>
  </entry>
  <entry><![CDATA[aaaa@bbb.ccc]]></entry>
  <entry><![CDATA[emailparent@ddd.eee]]></entry>
</result>
```

{% endtab %}
{% endtabs %}

#### Errors

{% tabs %}
{% tab title="json" %}

```json
{
    "success": false,
    "code": 10,
    "message": "Invalid API key"
}
```

{% endtab %}

{% tab title="xml" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<result>
    <entry>false</entry>
    <entry>10</entry>
    <entry>
        <![CDATA[Invalid API key]]>
    </entry>
</result>
```

{% endtab %}
{% endtabs %}

#### **Error Codes**

<table><thead><tr><th width="234">Response Code</th><th>Message</th></tr></thead><tbody><tr><td>1</td><td>The API key is required</td></tr><tr><td>2</td><td>You are not authorized to create sub-accounts</td></tr><tr><td>3</td><td><code>isBuyer</code> is required</td></tr><tr><td>4</td><td>The type is required (simple or advanced)</td></tr><tr><td>5</td><td>The sub-account type does not exist (simple or advanced)</td></tr><tr><td>6</td><td>The password must be at least 8 characters long</td></tr><tr><td>7</td><td>The email is required</td></tr><tr><td>8</td><td>The email is invalid</td></tr><tr><td>9</td><td>A sub-account already exists with this email</td></tr><tr><td>11</td><td>Your balance must be greater than 0</td></tr><tr><td>12</td><td>The credit to attribute must be greater than or equal to 0</td></tr><tr><td>13</td><td>An account already exists with this email</td></tr><tr><td>96</td><td>IP not authorized</td></tr><tr><td>200</td><td>Everything went fine!</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.docpartner.dev/en/api/mail-partner/sub-accounts/create-sub-account.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
