---
title: Cancel a payment initiation
slug: payment/cancel-a-payment-initiation
description: Learn how to cancel a payment initiation in Klavi API with this comprehensive document. Discover a step-by-step guide, including a sample curl command, request method, header, and path parameters. Explore the response code and JSON response example for a 
docTags: 
createdAt: 2023-05-18T20:29:45.000Z
---

:::ApiMethodV2
```json
{
  "name": "cancel",
  "method": "POST",
  "url": "https://api-sandbox.klavi.ai/payment/customer/v1/instant/payments/{id}/cancel",
  "description": "Cancel a payment initiation",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "zFcWiIkuyAefto91iRlvU",
        "language": "curl",
        "code": "curl --location --globoff 'https://api-sandbox.klavi.ai/instant/payment/customer/v1/payments/{id}/cancel/{id}' \\\n--header 'Accept: application/json' \\\n--header 'Content-Type: application/json' \\\n--data '{\n  \"cancelledBy\": \"String\",\n  \"identifierType\": \"String\"\n}'",
        "customLabel": ""
      },
      {
        "id": "VToPuD_J-YGBoMiq7HXta",
        "language": "nodejs",
        "code": "var request = require('request');\nvar options = {\n   'method': 'POST',\n   'url': 'https://api-sandbox.klavi.ai/payment/customer/v1/instant/payments/{id}/cancel/{id}',\n   'headers': {\n      'Accept': 'application/json',\n      'Content-Type': 'application/json'\n   },\n   body: JSON.stringify({\n      \"cancelledBy\": \"String\",\n      \"identifierType\": \"String\"\n   })\n\n};\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "IBY-Q342YLjaLHFdI6kAx",
        "language": "javascript",
        "code": "var myHeaders = new Headers();\nmyHeaders.append(\"Accept\", \"application/json\");\nmyHeaders.append(\"Content-Type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"cancelledBy\": \"String\",\n   \"identifierType\": \"String\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api-sandbox.klavi.ai/payment/customer/v1/instant/payments/{id}/cancel/{id}\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));",
        "customLabel": ""
      },
      {
        "id": "V7jutH35_G4gkmirlOn_Y",
        "language": "python",
        "code": "import requests\nimport json\n\nurl = \"https://api-sandbox.klavi.ai/payment/customer/v1/instant/payments/{id}/cancel/{id}\"\n\npayload = json.dumps({\n   \"cancelledBy\": \"String\",\n   \"identifierType\": \"String\"\n})\nheaders = {\n   'Accept': 'application/json',\n   'Content-Type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "customLabel": ""
      },
      {
        "id": "fCdp3V8cjcG7ijepn2Cep",
        "language": "ruby",
        "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api-sandbox.klavi.ai/payment/customer/v1/instant/payments/{id}/cancel/{id}\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"Accept\"] = \"application/json\"\nrequest[\"Content-Type\"] = \"application/json\"\nrequest.body = JSON.dump({\n   \"cancelledBy\": \"String\",\n   \"identifierType\": \"String\"\n})\n\nresponse = https.request(request)\nputs response.read_body\n",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "fCdp3V8cjcG7ijepn2Cep"
  },
  "results": {
    "languages": [
      {
        "id": "tD0B0QhIf-FzJLRBMYRNi",
        "language": "200",
        "customLabel": "",
        "code": ""
      }
    ],
    "selectedLanguageId": "tD0B0QhIf-FzJLRBMYRNi"
  },
  "request": {
    "pathParameters": [
      {
        "name": "id",
        "kind": "required",
        "type": "string",
        "description": "Payment initiation order id, it will be returned when POST /payments is called",
        "": "Payment initiation order id, it will be returned when POST /payments is called"
      }
    ],
    "queryParameters": [],
    "headerParameters": [
      {
        "name": "Authorization",
        "kind": "required",
        "type": "string",
        "description": "JWT bearer token",
        "children": []
      }
    ],
    "bodyDataParameters": [
      {
        "name": "cancelledBy",
        "kind": "required",
        "type": "string",
        "description": "The cpf of the user that wanted to cancel",
        "children": []
      },
      {
        "name": "identifierType",
        "kind": "required",
        "type": "string",
        "description": "Type of the user identification document: CNPJ or CPF",
        "": "Type of the user identification document: CNPJ or CPF"
      }
    ],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Body Parameter",
    "value": "bodyDataParameters"
  },
  "response": [],
  "hasTryItOut": false,
  "autoGeneratedAnchorSlug": "cancel",
  "legacyHash": "fVV_TaQyMudubJ5PERwKx"
}
```
:::

[​](https://docs.klavipay.ai/docs/api-reference/customer/payments/cancel-payment#code-200)

