> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.mangopay.com/api-reference/mandates/cancel-mandate/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mangopay.com/_mcp/server. # Cancel a Mandate PUT https://api.sandbox.mangopay.com/v2.01/{ClientId}/mandates/{MandateId}/cancel **Warning – Call requires `Content-Length` adjustment** For this call to succeed, you need to define the header `Content-Length` to `0`. **Note – Mandate must be `ACTIVE` or `SUBMITTED`** A mandate can only be canceled if its `Status` is `ACTIVE` or `SUBMITTED`. Once canceled, its status changes to `FAILED`. Cancel a Mandate Reference: https://docs.mangopay.com/api-reference/mandates/cancel-mandate ## Authentication - `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer `, where token is your auth token. If your platform is using a [proxy](/guides/sca/proxy-management) to take SCA-triggering action on behalf of users, you also need to integrate [mTLS authentication](/guides/sca/platform) and use the `api-mtls` base URL. ## Servers - `https://api.sandbox.mangopay.com` (Sandbox, default) - `https://api.mangopay.com` (Production) - `https://api-mtls.sandbox.mangopay.com` (mTLS Sandbox) - `https://api-mtls.mangopay.com` (mTLS Production) ## Request ### Path parameters - `ClientId` (string, required) — Platform's API account identifier, associated with the API key. - `MandateId` (string, required) — The unique identifier of the mandate. ## Response ### 200 Success - `Scheme` (string, optional) — 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. - `RecipientId` (string, optional) — The unique identifier of the [Recipient](/api-reference/recipients/recipient-object) object on which the mandate is based. This property should be used by platforms integrating for the first time (and not the `BankAccountId`). - `BankAccountId` (string, optional) — The unique identifier of the bank account. This property should **not** be used by platforms integrating for the first time – use the `RecipientId` instead. **Warning:** The Bank Account `Type` must be IBAN for the SEPA scheme and GB for the Bacs scheme. - `BankReference` (string, optional) — The banking reference for the Mandate. - `Culture` (string, optional) — **Returned values:** One of the supported languages in the [ISO 639-1 format](/api-reference/overview/data-formats): 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`. - `DocumentURL` (string, optional) — The URL at which the mandate document can be downloaded. - `ReturnURL` (string, optional) — Max. length: 220 characters The URL to which the user is returned after the payment, whether the transaction is successful or not. - `RedirectURL` (string, optional) — 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. - `Id` (string, optional) — Max length: 128 characters (see [data formats](/api-reference/overview/data-formats) for details) The unique identifier of the object. - `CreationDate` (integer, optional) — Unix timestamp (UTC) of the date and time the object was created. - `Status` (string, optional) — **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. - `UserId` (string, optional) — The unique identifier of the User (natural or legal) who owns the bank account. - `ExecutionType` (string, optional) — **Returned values:** `WEB` The execution type of the mandate. - `MandateType` (string, optional) — The type of the mandate. - `Tag` (string, optional) — Max. length: 255 characters Custom data that you can add to this object, such as unique identifiers in your system. To store multiple values, you can serialize them into a single string, for example a JSON object: `"{\"id_1\":AB123,\"id_2\":DE456}"`. - `ResultCode` (string, optional) — The code indicating the result of the operation. This information is mostly used to handle errors or for filtering purposes. - `ResultMessage` (string, optional) — The explanation of the result code. ## Errors ### 400 Bad Request Error Bad Request - `Message` (string, optional) — Description of the error. - `Type` (string, optional) — The category of the error. - `Id` (string, optional) — Unique identifier of the error instance, useful when contacting Mangopay for support. - `Date` (double, optional) — Unix timestamp (UTC) of the date and time the error was triggered. - `errors` (map from string to string, optional, nullable) — Object containing one or more field-level errors. ## Examples **Response** ```json { "Scheme": "SEPA", "RecipientId": "rec_01J999AWHFHW2PQ1ADNQ46AYE9", "BankAccountId": "bankacc_m_01J999AWHFHW2PQ1ADNQ46AYE9", "BankReference": "QYDZMNP", "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": "FAILED", "UserId": "user_m_01J8SY95DQ5CM7DH43NQCAS65T", "ExecutionType": "WEB", "MandateType": "DIRECT_DEBIT", "Tag": "Created using the Mangopay API Postman collection", "ResultCode": 1806, "ResultMessage": "The client has cancelled the mandate" } ``` **SDK Code** ```python 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 mandate = Mandate.get('214061194') cancel_mandate = mandate.cancel() pprint(cancel_mandate) ``` ```javascript const mangopayInstance = require('mangopay4-nodejs-sdk') const mangopay = new mangopayInstance({ clientId: 'your-client-id', clientApiKey: 'your-api-key', }) let myMandate = { Id: '192790303', } const cancelMandate = async (mandateId) => { return await mangopay.Mandates.cancel(mandateId) .then((response) => { console.info(response) return response }) .catch((err) => { console.log(err) return false }) } cancelMandate(myMandate.Id) ``` ```java import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mangopay.MangoPayApi; import com.mangopay.entities.Mandate; public class CancelMandate { 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 = mangopay.getMandateApi().cancel("mdt_m_01J1YS0HTE11FVT07V5TCZEG4P"); Gson prettyPrint = new GsonBuilder().setPrettyPrinting().create(); String prettyJson = prettyPrint.toJson(mandate); System.out.println(prettyJson); } } ``` ```csharp 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 mandateId = "mdt_m_01J3D0WJZ5TNYX1HE7PVSCETF0"; var cancelMandate = await api.Mandates.CancelAsync(mandateId); string prettyPrint = JsonConvert.SerializeObject(cancelMandate, Formatting.Indented); Console.WriteLine(prettyPrint); } } ``` ```php Config->ClientId = 'your-client-id'; $api->Config->ClientPassword = 'your-api-key'; $api->Config->TemporaryFolder = 'tmp/'; try { $mandateId = '199255586'; $response = $api->Mandates->Cancel($mandateId); print_r($response); } catch(MGPResponseException $e) { print_r($e); } catch(MGPException $e) { print_r($e); } ``` ```ruby 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 cancelMandate(mandateId) begin response = MangoPay::Mandate.cancel(mandateId) puts response return response rescue MangoPay::ResponseError => error puts "Failed to cancel mandate: #{error.message}" puts "Error details: #{error.details}" return false end end myMandate = { Id:'194337135' } cancelMandate(myMandate[:Id]) ```