> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mangopay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Mandate

<Note>
  **Note – Mandate expires after 1 hour**

  If not confirmed within 1 hour of the `CreationDate`, the Mandate expires with the error <a href="/errors/codes/001807">001807</a> and a new one must be created.
</Note>

For SDD, if the `BankAccountId` is a Danish or Swedish IBAN (starting `DK` or `SE`), this endpoint returns a 400 error because they are not currently supported (see [IBAN compatibility](/guides/payment-methods/banking/direct-debit#iban-compatibility)).

### Body parameters

<ParamField body="BankAccountId" type="string" required>
  The unique identifier of the bank account.

  **Warning:** The <a href="/api-reference/bank-accounts/bank-account-object">Bank Account</a> `Type` must be IBAN for the SEPA scheme and GB for the Bacs scheme.
</ParamField>

<ParamField body="Culture" type="string" required>
  **Allowed values:** One of the supported languages in the <a href="/api-reference/overview/data-formats">ISO 639-1 format</a>: DE, EN, ES, FR, IT, NL, PL

  The language in which the mandate confirmation page is to be displayed. This value only applies to mandates with the SEPA `Scheme`.
</ParamField>

<ParamField body="ReturnURL" type="string" required>
  Max. length: 220 characters

  The URL to which the user is returned after the payment, whether the transaction is successful or not.
</ParamField>

<ParamField body="Tag" type="string">
  Max. length: 255 characters

  Custom data that you can add to this object.
</ParamField>

### Responses

<Accordion title="200">
  <ResponseField name="Scheme" type="string">
    The scheme of the mandate, which is available once the mandate is submitted. The value can be one of the following: 

    * BACS – Covers payments in the UK, in GBP only.
    * SEPA – Covers payments in the EU.
  </ResponseField>

  <ResponseField name="BankAccountId" type="string">
    The unique identifier of the bank account.

    **Warning:** The <a href="/api-reference/bank-accounts/bank-account-object">Bank Account</a> `Type` must be IBAN for the SEPA scheme and GB for the Bacs scheme.
  </ResponseField>

  <ResponseField name="BankReference" type="string">
    The banking reference for the Mandate.
  </ResponseField>

  <ResponseField name="Culture" type="string">
    **Returned values:** One of the supported languages in the <a href="/api-reference/overview/data-formats">ISO 639-1 format</a>: DE, EN, ES, FR, IT, NL, PL

    The language in which the mandate confirmation page is to be displayed. This value only applies to mandates with the SEPA `Scheme`.
  </ResponseField>

  <ResponseField name="DocumentURL" type="string">
    The URL at which the mandate document can be downloaded.
  </ResponseField>

  <ResponseField name="ReturnURL" type="string">
    Max. length: 220 characters

    The URL to which the user is returned after the payment, whether the transaction is successful or not.
  </ResponseField>

  <ResponseField name="RedirectURL" type="string">
    The URL to which to redirect the user to complete the payment.

    **Caution:** This variable URL is specific to each payment. You must rely on the returned URL in full (host, path, and queries) and not hardcode any part of it.
  </ResponseField>

  <ResponseField name="Id" type="string">
    Max length: 128 characters (see [data formats](/api-reference/overview/data-formats) for details)

    The unique identifier of the object.
  </ResponseField>

  <ResponseField name="CreationDate" type="Unix timestamp">
    The date and time at which the object was created.
  </ResponseField>

  <ResponseField name="Status" type="string">
    **Returned values:** `CREATED`, `SUBMITTED`, `ACTIVE`, `FAILED`, `EXPIRED`

    The status of the mandate:

    * `CREATED` – The mandate has been generated but not yet confirmed.
    * `SUBMITTED` – The mandate has been confirmed and sent to the user's bank, and can be used to request a direct debit pay-in.
    * `ACTIVE` – The mandate has been accepted by the user's bank or successfully used to process a direct debit direct pay-in. Further pay-ins can be requested.
    * `FAILED` – The mandate has been canceled or otherwise failed, and can no longer be used for payments.
    * `EXPIRED` – No payment has been made against the mandate in the last 24 months. It can no longer be used for payments.
  </ResponseField>

  <ResponseField name="UserId" type="string">
    The unique identifier of the User (natural or legal) who owns the bank account.
  </ResponseField>

  <ResponseField name="ExecutionType" type="string">
    **Returned values:** `WEB`

    The execution type of the mandate.
  </ResponseField>

  <ResponseField name="MandateType" type="string">
    The type of the mandate.
  </ResponseField>

  <ResponseField name="Tag" type="string">
    Max. length: 255 characters

    Custom data that you can add to this object.
  </ResponseField>

  <ResponseField name="ResultCode" type="string">
    The code indicating the result of the operation. This information is mostly used to <a href="/errors/codes">handle errors</a> or for filtering purposes.
  </ResponseField>

  <ResponseField name="ResultMessage" type="string">
    The explanation of the result code.
  </ResponseField>
</Accordion>

<Accordion title="400 - For SDD, IBAN country not supported">
  ```json theme={null}
  {
      "Message": "One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.",
      "Type": "param_error",
      "Id": "c0f5f61a-d752-4dd8-816d-fd3c34595c5d#1771499159",
      "Date": 1771499160,
      "errors": {
          "BankAccountId": "The IBAN bank account is not accepted for this country and currency"
      }
  }
  ```
</Accordion>

<Accordion title="400 - EN only for BACS">
  ```json theme={null}
  {
     "Message": "One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.",
     "Type": "param_error",
     "Id": "277c7c4e-baf1-43f8-ba1d-d9f02d7939e2",
     "Date": 1727958031.0,
     "errors": {
         "Culture": "The requested language is not supported for this bank account"
     }
  }  
  ```
</Accordion>

<Accordion title="400 - Language not supported">
  ```json theme={null}
  {
      "Message": "One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.",
      "Type": "param_error",
      "Id": "9d45b954-4eda-4247-b4e3-91027628ab22",
      "Date": 1690294898.0,
      "errors": {
          "Culture": "The requested language is not supported"
      }
  }  
  ```
</Accordion>

<ResponseExample>
  ```json 200   theme={null}
  {
      "Scheme": null,
      "BankAccountId": "bankacc_m_01J999AWHFHW2PQ1ADNQ46AYE9",
      "BankReference": null,
      "Culture": "EN",
      "DocumentURL": "https://api.sandbox.mangopay.com/webhook/eu/public/mandates/e8a73d/dfbdce2a12a442bfae973e56777b3ddb/document?version=2.01",
      "ReturnURL": "http://example.com?MandateId=mdt_m_01J999B9HSEDH9CZDEXXYZGHEZ",
      "RedirectURL": "https://api.sandbox.mangopay.com/mvc/eu/public/mandates/e8a73d/dfbdce2a12a442bfae973e56777b3ddb/confirmation?version=2.01",
      "Id": "mdt_m_01J999B9HSEDH9CZDEXXYZGHEZ",
      "CreationDate": 1727962392,
      "Status": "CREATED",
      "UserId": "user_m_01J8SY95DQ5CM7DH43NQCAS65T",
      "ExecutionType": "WEB",
      "MandateType": "DIRECT_DEBIT",
      "Tag": "Created using the Mangopay API Postman collection",
      "ResultCode": null,
      "ResultMessage": null
  }
  ```
</ResponseExample>

<RequestExample>
  ```json REST   theme={null}
  {
      "BankAccountId": "bankacc_m_01J999AWHFHW2PQ1ADNQ46AYE9",
      "Culture": "EN",
      "ReturnURL": "http://example.com",
      "Tag": "Created using the Mangopay API Postman collection"
  }
  ```

  ```php PHP theme={null}
  <?php 

  require_once 'vendor/autoload.php';

  use MangoPay\MangoPayApi;
  use MangoPay\Libraries\ResponseException as MGPResponseException;
  use MangoPay\Libraries\Exception as MGPException;

  $api = new MangoPayApi();

  $api->Config->ClientId = 'your-client-id';
  $api->Config->ClientPassword = 'your-api-key';
  $api->Config->TemporaryFolder = 'tmp/';

  try {
      $bankAccountId = '198982529'; 

      $mandate = new \MangoPay\Mandate();
      $mandate->BankAccountId = $bankAccountId;
      $mandate->Culture = 'EN'; 
      $mandate->ReturnURL = 'http://example.com';
      $mandate->Tag = 'Created using Mangopay PHP SDK';
      
      $response = $api->Mandates->Create($mandate);

      print_r($response);
  } catch(MGPResponseException $e) {
      print_r($e);
  } catch(MGPException $e) {
      print_r($e);
  }  
  ```

  ```javascript NodeJS   theme={null}
  const mangopayInstance = require('mangopay4-nodejs-sdk')
  const mangopay = new mangopayInstance({
    clientId: 'your-client-id',
    clientApiKey: 'your-api-key',
  })

  let myMandate = {
    BankAccountId: '151467634',
    Culture: 'EN',
    ReturnUrl: 'http://example.com',
  }

  const createMandate = async (mandate) => {
    return await mangopay.Mandates.create(mandate)
      .then((response) => {
        console.info(response)
        return response
      })
      .catch((err) => {
        console.log(err)
        return false
      })
  }

  createMandate(myMandate)  
  ```

  ```ruby Ruby   theme={null}
  require 'mangopay'

  MangoPay.configure do |client|
      client.preproduction = true
      client.client_id = 'your-client-id'
      client.client_apiKey = 'your-api-key'
      client.log_file = File.join(Dir.pwd, 'mangopay.log')
  end

  def createMandate(mandateObject)
      begin
          response = MangoPay::Mandate.create(mandateObject)
          puts response
          return response
      rescue MangoPay::ResponseError => error
          puts "Failed to create mandate: #{error.message}"
          puts "Error details: #{error.details}"
          return false
      end
  end

  myMandate = {
      BankAccountId:'151453487',
      Culture:'EN',
      ReturnURL:'http://example.com',
      Tag:'Created using Mangopay Ruby SDK'
  }

  createMandate(myMandate)  
  ```

  ```java Java  theme={null}
  import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import com.mangopay.MangoPayApi;
  import com.mangopay.core.enumerations.CultureCode;
  import com.mangopay.entities.Mandate;

  public class CreateMandate {
      public static void main(String[] args) throws Exception {
          MangoPayApi mangopay = new MangoPayApi();
          mangopay.getConfig().setClientId("your-client-id");
          mangopay.getConfig().setClientPassword("your-api-key");
          
          Mandate mandate = new Mandate();
          mandate.setBankAccountId("bankacc_m_01HW2YJFFGYMY4HHHQSZ9YBCQJ");
          mandate.setReturnUrl("https://www.mangopay.com/docs/please-ignore");
          mandate.setCulture(CultureCode.EN);
          mandate.setTag("Created using the Mangopay Java SDK");


          Mandate createMandate = mangopay.getMandateApi().create(mandate);

          Gson prettyPrint = new GsonBuilder().setPrettyPrinting().create();
          String prettyJson = prettyPrint.toJson(createMandate);

          System.out.println(prettyJson);
      }
  }
  ```

  ```python Python   theme={null}
  from pprint import pprint
  import mangopay

  mangopay.client_id='your-client-id'
  mangopay.apikey='your-api-key'

  from mangopay.api import APIRequest
  handler = APIRequest(sandbox=True)

  from mangopay.resources import Mandate

  bank_account_id = '214050174'

  mandate = Mandate(
      bank_account_id = bank_account_id,
      culture = 'EN',
      return_url = 'http://example.com',
      tag = 'Created using the Mangopay Python SDK'
  )

  create_mandate = mandate.save()

  pprint(create_mandate)  
  ```

  ```csharp .NET  theme={null}
  using MangoPay.SDK;
  using MangoPay.SDK.Entities.PUT;
  using Newtonsoft.Json;

  class Program
  {
      static async Task Main(string[] args)
      {
          MangoPayApi api = new MangoPayApi();

          api.Config.ClientId = "your-client-id";
          api.Config.ClientPassword = "your-api-key";

          var bankAccountId = "bankacc_m_01J3D0VAFPEAFA42S9A641M91Z";
          var returnUrl = "https://www.mangopay.com/docs/please-ignore/";

          var mandate = new MandatePostDTO(bankAccountId, CultureCode.EN, returnUrl);

          var createMandate = await api.Mandates.CreateAsync(mandate);

          string prettyPrint = JsonConvert.SerializeObject(createMandate, Formatting.Indented);
          Console.WriteLine(prettyPrint);
      }
  }
  ```
</RequestExample>
