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

# Close a Legal User

> Permanently close a user account so it can no longer be used

This endpoint allows your platform to close a Mangopay Account, as per Mangopay's <a href="https://mangopay.com/terms-and-conditions" target="_blank">terms and conditions</a>, in the event that the agreement between the user and the platform comes to an end.

<Warning>
  **Caution – Closure is irreversible**

  Calling this endpoint immediately and permanently changes the `UserStatus` to `CLOSED` if the API call is successful. This cannot be undone, even by Mangopay.

  Your platform can re-register the user using [POST Create a Legal User (SCA)](/api-reference/users/create-legal-user-sca).
</Warning>

Closure is only possible if all wallets held by the user are empty. Closure is allowed for both `UserCategory` `OWNER` and `PAYER` and for all types of Legal user (Business, Partnership, Organization, Soletrader).

When a User is closed (whether via this endpoint or by Mangopay):

* The `UserStatus` changes to `CLOSED` (and the `USER_ACCOUNT_CLOSED` [webhook](/webhooks/event-types#account-closure) is sent)
* The user has inflows and outflows [blocked](/guides/users/blocked-users) (and the relevant [webhooks](/webhooks/event-types#user-regulatory-status) are sent)
* The user object remains available via the API and Dashboard for historical purposes

Closing a user account does not affect Mangopay's data retention obligations or processes. Personal data associated with the closed account will be retained in accordance with Mangopay's data retention policies.

<Note>
  **Note – Do not overuse OAuth token endpoint if automating calls**

  If you are writing a script to close a set of users, ensure you do not call the OAuth token endpoint before each DELETE call. You must use your authentication for the full duration of its lifetime, as described in the [authentication](/api-reference/overview/authentication#2-use-the-bearer-token-for-its-full-lifetime) guide.

  Overuse of the OAuth token endpoint is a security and performance risk and may result in preventative action from Mangopay.
</Note>

### Path parameters

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

### Responses

<AccordionGroup>
  <Accordion title="204 - No Content" defaultOpen>
    The 204 response code indicates that the closure request was successful.
  </Accordion>
</AccordionGroup>

<AccordionGroup>
  <Accordion title="400 - Wallets not empty">
    ```json theme={null}
    {
        "Message": "The user cannot be closed as one or several wallets are not empty",
        "Type": "user_closure_not_possible",
        "Id": "bcb91dae-bb4a-4f99-937c-8f8530c14a31#1744636047",
        "Date": 1744636048,
        "errors": null
    }
    ```
  </Accordion>

  <Accordion title="400 - User already closed">
    ```json theme={null}
    {
        "Message": "An error occurred while closing the user",
        "Type": "user_closure_failed",
        "Id": "8524ae5f-3232-4910-b9db-4ffd7f4be4ee",
        "Date": 1744631045,
        "errors": null
    }
    ```
  </Accordion>
</AccordionGroup>

<RequestExample>
  ```json REST theme={null}
  // DELETE has no body parameters
  ```

  ```php PHP theme={null}
  <?php
  require_once 'vendor/autoload.php';

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

  $api = new MangoPayApi();

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

  try {
      $userLegal = $api->Users->GetLegalSca('user_m_01K8932FJ54AF8BY7PY80G0JG1');

      $api->Users->Close($userLegal);
      
      $afterClose = $api->Users->GetLegalSca('user_m_01K8932FJ54AF8BY7PY80G0JG1');

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

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

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

  def closeLegalUserSca(userId)
    begin
      response = MangoPay::LegalUser.close(userId)
      puts response
      return response
    rescue MangoPay::ResponseError => error
      puts "Failed to close User: #{error.message}"
      puts "Error details: #{error.details}"
      return false
    end
  end

  closeLegalUserSca('user_m_01K85X5HKK3YD61Y3YXD9FHV7H')
  ```

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

  public class CloseUser
  {
      public void Run()
      {
          Task.Run(async () =>
          {
              MangoPayApi api = new MangoPayApi();

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

              await api.Users.CloseLegalAsync("user_m_01K8B3WYXFGHKZZSN4DCEDJC69");
              var closed =
                  await api.Users.GetScaAsync("user_m_01K8B3WYXFGHKZZSN4DCEDJC69");

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

<ResponseExample>
  ```json 204 theme={null}
  ```
</ResponseExample>
