> 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/voice-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.voicepartner.fr/v1/subaccount/create`

Rate limit: 30 requests / 60 seconds *(see* [Rate limiting)](/en/api/sms-partner/rate-limiting.md)*)*

#### **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.voicepartner.fr/app/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 or SMS.<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@voicepartner.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 then the sub-account can purchase its own SMS</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 fullWidth="true" %}
{% 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.voicepartner.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.smspartner.fr/v1/"
    Dim apiKey As String = "YOUR_APIKEY"
 
    #send sms
    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.smspartner.fr/v1"
 
class SMSPartner():
    def create(self,creditToAdd,userId):
 
		data = {"apiKey":APIKEY,"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.smspartner.fr/v1/subaccount/create
```

{% endtab %}

{% tab title="Nodejs" %}

```javascript
const https = require("https");

// Replace with your API key
const apiKey = "YOUR_API_KEY";

// Prepare the data for the POST request
const data = JSON.stringify({
  apiKey: apiKey,
  type: "advanced",
  parameters: {
    email: "aaaa@bbb.ccc",
    creditToAttribute: 10,
    isBuyer: 0,
    firstname: "firstname",
    lastname: "lastname",
  },
});

// Define the options for the HTTP POST request to the SMS Partner API
const options = {
  hostname: "api.smspartner.fr",
  port: 443,
  path: "/v1/subaccount/create",
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Content-Length": data.length,
    "cache-control": "no-cache",
  },
};

// Perform the HTTP POST request with the options and data defined above
const req = https.request(options, (res) => {
  console.log(`statusCode: ${res.statusCode}`);

  // Print the API response data to standard output
  res.on("data", (d) => {
    process.stdout.write(d);
  });
});

// Print an error if the HTTP POST request fails
req.on("error", (error) => {
  console.error(error);
});

// Send the 'data' object's content with the request
req.write(data);
// End the HTTP POST request
req.end();
```

{% endtab %}

{% tab title="JAVA" %}

```java
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import org.json.JSONObject;


public class SubAccountCreation {
    public static void main(String[] args) {
        try {
            // Replace with your API key
            String apiKey = "YOUR_API_KEY";

            // Prepare the data for the POST request
            JSONObject parameters = new JSONObject();
            parameters.put("email", "aaaa@bbb.ccc");
            parameters.put("creditToAttribute", 10);
            parameters.put("isBuyer", 0);
            parameters.put("firstname", "firstname");
            parameters.put("lastname", "lastname");

            JSONObject json = new JSONObject();
            json.put("apiKey", apiKey);
            json.put("type", "advanced");
            json.put("parameters", parameters);

            URL url = new URL("https://api.smspartner.fr/v1/subaccount/create");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setRequestProperty("cache-control", "no-cache");
            conn.setDoOutput(true);

            // Write the JSON data to the HTTP request body
            OutputStream os = conn.getOutputStream();
            os.write(json.toString().getBytes());
            os.flush();

            // Read the API response
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String response = br.lines().collect(Collectors.joining());

            // Print the JSON response
            System.out.println(response);

            // Close the HTTP connection
            conn.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
import SwiftUI

// Structure for the "CreateSubAccount" view
struct CreateSubAccount: View {
    var body: some View {
        // A button that calls the createSubaccount() function when pressed
        Button(action: {
            createSubaccount()
        }) {
            Text("Create sub-account")
                .font(.system(size: 20))
                .foregroundColor(.white)
                .frame(minWidth: 0, maxWidth: .infinity)
                .padding()
                .background(LinearGradient(gradient: Gradient(colors: [Color.blue, Color.blue.opacity(0.8)]), startPoint: .top, endPoint: .bottom))
                .cornerRadius(10)
                .padding(.horizontal)
        }
    }

    // Function to create a sub-account
    func createSubaccount() {
        let url = URL(string: "https://api.smspartner.fr/v1/subaccount/create")! // URL to create a sub-account

        // Parameters for the request
        let parameters: [String: Any] = [
            "apiKey": "YOUR_API_KEY", // Your API key
            "type": "advanced",
            "parameters": [
                "email": "aaaa@bbb.ccc", // Sub-account email address
                "creditToAttribute": 10, // Credit to assign
                "isBuyer": 0, // Indicates whether the sub-account is a buyer
                "firstname": "firstname", // Sub-account user's first name
                "lastname": "lastname" // Sub-account user's last name
            ] as [String : Any]
        ]

        // Build the request
        var request = URLRequest(url: url)
        request.httpMethod = "POST"
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.setValue("no-cache", forHTTPHeaderField: "cache-control")

        // Add the request body
        do {
            request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
        } catch let error {
            print(error.localizedDescription)
        }

        // Task to send the request and receive the response
        let task = URLSession.shared.dataTask(with: request) { data, response, error in
            // If an error occurs, print it
            if let error = error {
                print("Error: \(error)")
            }
            // Otherwise, process the received data
            else if let data = data {
                do {
                    // Try to convert the received data to JSON
                    if let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any] {
                        print(json) // Print the resulting JSON
                    }
                } catch let error {
                    print("Error: \(error)")
                }
            }
        }

        task.resume() // Start the task
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"log"
	"net/http"
)

type Fields struct {
	APIKey     string      `json:"apiKey"`
	Type       string      `json:"type"`
	Parameters Parameters `json:"parameters"`
}

type Parameters struct {
	Email            string `json:"email"`
	CreditToAttribute int    `json:"creditToAttribute"`
	IsBuyer          int    `json:"isBuyer"`
	Firstname        string `json:"firstname"`
	Lastname         string `json:"lastname"`
}

func main() {
	// Prepare data for POST request
	data := Fields{
		APIKey: "YOUR_API_KEY",
		Type:   "advanced",
		Parameters: Parameters{
			Email:            "aaaa@bbb.ccc",
			CreditToAttribute: 10,
			IsBuyer:          0,
			Firstname:        "firstname",
			Lastname:         "lastname",
		},
	}

	payloadBuf := new(bytes.Buffer)
	json.NewEncoder(payloadBuf).Encode(data)

	// Create POST request
	req, err := http.NewRequest("POST", "https://api.smspartner.fr/v1/subaccount/create", payloadBuf)
	if err != nil {
		log.Fatalf("Error creating request: %v", err)
	}
	req.Header.Add("Content-Type", "application/json")

	// Create HTTP client and send the request
	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatalf("Error sending request: %v", err)
	}
	defer resp.Body.Close()

	// Read the response
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatalf("Error reading response: %v", err)
	}

	// Print the response status and body
	log.Printf("Response status: %s", resp.Status)
	log.Printf("Response body: %s", string(body))
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

class Program
{
    private static readonly HttpClient client = new HttpClient();

    static async Task Main(string[] args)
    {
        var fields = new
        {
            apiKey = "YOUR_API_KEY",
            type = "advanced",
            parameters = new 
            {
                email = "aaaa@bbb.ccc",
                creditToAttribute = 10,
                isBuyer = 0,
                firstname = "firstname",
                lastname = "lastname"
            }
        };

        var json = JsonConvert.SerializeObject(fields);

        var uri = new Uri("https://api.smspartner.fr/v1/subaccount/create");
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        HttpResponseMessage response = await client.PostAsync(uri, content);

        if (response.IsSuccessStatusCode)
        {
            var result = await response.Content.ReadAsStringAsync();
            Console.WriteLine(result);
        }
        else
        {
            Console.WriteLine("The POST request failed with status code: " + response.StatusCode);
        }
    }
}
```

{% 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>The phone number is required</td></tr><tr><td>3</td><td>isBuyer 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 email is required</td></tr><tr><td>7</td><td>An account already exists with this email</td></tr><tr><td>8</td><td>creditToAttribute must be greater than 0</td></tr><tr><td>9</td><td>The balance must be greater than 0</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/voice-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.
