> 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/manage-sub-account-credits.md).

# Manage Sub-account Credits

These requests are used to add or remove credits from a sub-account.

## Add credits

{% hint style="info" %}
From your account, you can add credits to your sub-accounts. The credits will be debited from your main account.
{% endhint %}

### URL

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

#### **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>credit</code></td><td>Amount of credit in euros to add to the sub-account</td></tr><tr><td><code>tokenSubaccount</code></td><td>Sub-account identifier</td></tr></tbody></table>

#### Requests

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

```php
<?php
        // Prepare data for POST request
        $fields = array(
            'apiKey'=> 'YOUR API KEY',
            'credit'=> '100',
            'tokenSubaccount'=>'sub-account identifier'
            );
 
 
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL,'https://api.mailpartner.fr/v1/subaccount/credit/add');
        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"
 
    #add credits to a sub-account
    url = base_url & "subaccount/credit/add"
    #note: use a JSON library in production, for example:
    #https//www.nuget.org/packages/Newtonsoft.Json/
    Dim parameters As String = String.Format(
        "{{""apiKey"":""{0}"",""credit"":""{1}"",""tokenSubaccount"":""{2}""}}",
        apiKey,
        50,
        "sub-account identifier")
    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 add_credit(self,creditToAdd,tokenSubaccount):
 
		data = OrderedDict([
			("apiKey", API_KEY),
			("credit",creditToAdd),
			("tokenSubaccount",tokenSubaccount)
 
		])
 
		url = URL + "/subaccount/credit/add"
		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","credit":"10","tokenSubaccount":"sub-account identifier"}' https://api.mailpartner.fr/v1/subaccount/credit/add
```

{% endtab %}
{% endtabs %}

#### **Response**

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

```json
{
    "success": true,
    "code": 200,
    "credit": 2869.2,
    "subaccountCredit": 61.8,
    "currency": "EUR"
}
```

{% endtab %}

{% tab title="xml" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<result>
    <entry>true</entry>
    <entry>200</entry>
    <entry>2859.2</entry>
    <entry>71.8</entry>
    <entry>
        <![CDATA[EUR]]>
    </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 manage sub-accounts</td></tr><tr><td>3</td><td>The credit is required</td></tr><tr><td>4</td><td>The sub-account identifier (<code>tokenSubaccount</code>) is required</td></tr><tr><td>5</td><td>The credit must be greater than 0</td></tr><tr><td>6</td><td>The sub-account was not found</td></tr><tr><td>7</td><td>The balance must be greater than 0</td></tr><tr><td>9</td><td>You are not authorized to assign credits</td></tr><tr><td>10</td><td>Invalid API key</td></tr><tr><td>96</td><td>IP not authorized</td></tr><tr><td>200</td><td>Everything went fine!</td></tr></tbody></table>

## Remove credits

{% hint style="info" %}
From your account, you can remove credits from your sub-accounts. The credits will be added to your main account.
{% endhint %}

### URL

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

#### **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>credit</code></td><td>Amount of credit in euros to remove from the sub-account</td></tr><tr><td><code>tokenSubaccount</code></td><td>Sub-account identifier</td></tr></tbody></table>

#### Requests

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

```php
<?php
        // Prepare data for POST request
        $fields = array(
            'apiKey'=> 'YOUR API KEY',
            'credit'=> '100',
            'tokenSubaccount'=>'sub-account identifier'
            );
 
 
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL,'https://api.mailpartner.fr/v1/subaccount/credit/remove');
        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"
 
    #remove credits from a sub-account
    url = base_url & "subaccount/credit/remove"
    #note: use a JSON library in production, for example:
    #https//www.nuget.org/packages/Newtonsoft.Json/
    Dim parameters As String = String.Format(
        "{{""apiKey"":""{0}"",""credit"":""{1}"",""tokenSubaccount"":""{2}""}}",
        apiKey,
        50,
        "sub-account identifier")
    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 remove_credit(self,creditToRemove,tokenSubaccount):
 
		data = OrderedDict([
			("apiKey", API_KEY),
			("credit",creditToRemove),
			("tokenSubaccount",tokenSubaccount)
 
		])
 
		url = URL + "/subaccount/credit/remove"
		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","credit":"10","tokenSubaccount":"sub-account identifier"}' https://api.mailpartner.fr/v1/subaccount/credit/remove
```

{% endtab %}
{% endtabs %}

#### **Response**

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

```json
{
    "success": true,
    "code": 200,
    "credit": 2869.2,
    "subaccountCredit": 61.8,
    "currency": "EUR"
}
```

{% endtab %}

{% tab title="xml" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<result>
    <entry>true</entry>
    <entry>200</entry>
    <entry>2859.2</entry>
    <entry>71.8</entry>
    <entry>
        <![CDATA[EUR]]>
    </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 manage sub-accounts</td></tr><tr><td>3</td><td>The credit is required</td></tr><tr><td>4</td><td>The sub-account identifier (<code>tokenSubaccount</code>) is required</td></tr><tr><td>5</td><td>The credit must be greater than 0</td></tr><tr><td>6</td><td>The sub-account was not found</td></tr><tr><td>7</td><td>The balance must be greater than 0</td></tr><tr><td>9</td><td>You are not authorized to assign credits</td></tr><tr><td>10</td><td>Invalid API key</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/manage-sub-account-credits.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.
