> ## 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.

# List Mandates for a Bank Account

### Path parameters

<ParamField path="UserId" type="string" required>
  The unique identifier of the user.
</ParamField>

<ParamField path="BankAccountId" type="string" required>
  The unique identifier of the bank account.\
  Warning: The corresponding Bank Account must belong to the BACS network (GB-type Bank Account) or SEPA network (IBAN-type Bank Account).
</ParamField>

### Responses

<AccordionGroup>
  <Accordion title="200">
    <ResponseField name="Array (Mandates)" type="array">
      The list of mandates created by the platform.

      <Expandable title="properties">
        <ResponseField name="Object (Mandate)" type="object">
          The mandate created by the platform.

          <Expandable title="properties">
            <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="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>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Accordion>
</AccordionGroup>

<ResponseExample>
  ```json 200   theme={null}
  [
      {
          "Id": "mdt_m_01J98YZT8AJBGWX47AA077XMKZ",
          "CreationDate": 1663244376,
          "Status": "FAILED",
          "UserId": "user_m_01J8SY95DQ5CM7DH43NQCAS65T",
          "ExecutionType": "WEB",
          "MandateType": "DIRECT_DEBIT",
          "Tag": "Created using the Mangopay API Postman collection",
          "ResultCode": "001807",
          "ResultMessage": "User has let the mandate session expire without confirming"
      },
      {
          "Id": "mdt_m_01J999B9HSEDH9CZDEXXYZGHEZ",
          "CreationDate": 1669040333,
          "Status": "ACTIVE",
          "UserId": "user_m_01J8SY95DQ5CM7DH43NQCAS65T",
          "ExecutionType": "WEB",
          "MandateType": "DIRECT_DEBIT",
          "Tag": "Created using the Mangopay API Postman collection",
          "ResultCode": "000000",
          "ResultMessage": "Success"
      }
  ]
  ```
</ResponseExample>

<RequestExample>
  ```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 = '151467634';
      
      $response = $api->Users->GetMandates($bankAccountId);

      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 user = {
    Id: '151452401',
  }
  let bankAccount = {
    Id: '151467634',
  }

  const listBankAccountMandates = async (userId, bankAccountId) => {
    return await mangopay.Mandates.getMandatesForBankAccount(
      userId,
      bankAccountId
    )
      .then((response) => {
        console.info(response)
        return response
      })
      .catch((err) => {
        console.log(err)
        return false
      })
  }

  listBankAccountMandates(user.Id, bankAccount.Id)  
  ```

  ```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 listMandatesBankAccount(userId, bankAccountId)
      begin
          response = MangoPay::Mandate.fetch_for_user_bank_account(userId, bankAccountId)
          puts response
          return response
      rescue MangoPay::ResponseError => error
          puts "Failed to fetch Mandates: #{error.message}"
          puts "Error details: #{error.details}"
          return false
      end
  end

  myUser = {
      Id:'146476890'
  }

  myBankAccount = {
      Id: '194612216'
  }

  listMandatesBankAccount(myUser[:Id], myBankAccount[:Id])  
  ```

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

  public class ListBankAccountMandates {
      public static void main(String[] args) throws Exception {

       MangoPayApi mangopay = new MangoPayApi();
       mangopay.getConfig().setClientId("your-client-id");
       mangopay.getConfig().setClientPassword("your-api-key");

       var userId = "user_m_01HT2NFK7Z2BRQNGNHMY30VVTT";
       var bankAccountId = "bankacc_m_01HW2YM8ZYJTVHJZENNXK33HYB";
          
       List<Mandate> mandates = mangopay.getMandateApi().getForBankAccount(userId, bankAccountId, null, null, null);

       for (Mandate mandate : mandates) {
              Gson prettyPrint = new GsonBuilder().setPrettyPrinting().create();
              String prettyJson = prettyPrint.toJson(mandate);

              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 BankAccount

  natural_user_id = '213753890'

  bank_account_id = '214050174'

  bank_account = BankAccount.get(reference = bank_account_id, user_id = natural_user_id)

  mandates = bank_account.get_mandates()

  for mandate in mandates:
      pprint(vars(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 userId = "user_m_01J2TZ261WZNDM0ZDRWGDYA4GN";
          var bankAccountId = "bankacc_m_01J3D0VAFPEAFA42S9A641M91Z";

          var viewBankAccountMandates = await api.Mandates.GetForBankAccountAsync(userId, bankAccountId, new Pagination(1, 100), null);

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