---
title: Validate OTP
slug: single-connect-api-3-0-3/validate-otp
description: Learn how to validate OTP (One-Time Password) by making a secure POST request with this code example. The comprehensive guide covers the necessary headers and form data parameters, using the powerful curl command to ensure successful verification. Boost y
docTags: 
createdAt: 2022-11-10T14:21:49.000Z
---

{
  "id": "yFGvBfNebH17ZgAMhU1Oj",
  "data": {
    "url": "{{url}}/twofactorauth-ui/rest/tfa/otpValid",
    "method": "POST",
    "request": {
      "pathParameters": [],
      "queryParameters": [],
      "headerParameters": [
        {
          "name": "Content-Type",
          "type": "string",
          "example": "application/x-www-form-urlencoded",
          "description": ""
        },
        {
          "name": "X-XSRF-TOKEN",
          "type": "string",
          "example": "{{csrftoken}}",
          "description": ""
        }
      ],
      "bodyDataParameters": [],
      "formDataParameters": [
        {
          "name": "username",
          "type": "string",
          "example": "admin",
          "description": ""
        },
        {
          "name": "token",
          "type": "string",
          "example": "183942",
          "description": ""
        },
        {
          "name": "ignoreUsedBefore",
          "type": "string",
          "example": "true",
          "description": "this field allows a token to be used multiple times in validity time period. The field takes \"true\" or \"false\" values"
        }
      ]
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "Validate OTP",
        "jsonExample": ""
      }
    ],
    "contentType": "application/json",
    "description": "<p>This method is used to validate OTP (One Time Password) for a user. Parameters should be sent in request body as URL Encoded.</p>\n<p>available parameters:\nusername //mandatory field\ntoken\napplicationName</p>",
    "examples": {
      "languages": [
        {
          "id": "CDKlipO92kBRqCg8P3BeD",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url {{url}}/twofactorauth-ui/rest/tfa/otpValid \\\n     --header 'accept: application/json'"
        },
        {
          "id": "ys_i4G0icWjy8uEdoJ_XI",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"{{url}}/twofactorauth-ui/rest/tfa/otpValid\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "DGIPydvyN2RFe8JBYjiRl",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"{{url}}/twofactorauth-ui/rest/tfa/otpValid\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "GOkApgzaKClB_GLjQ_bYm",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"{{url}}/twofactorauth-ui/rest/tfa/otpValid\"\n\npayload = {}\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"
        }
      ],
      "selectedLanguageId": "CDKlipO92kBRqCg8P3BeD"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Validate OTP\n"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "type": "api-oas-v2",
  "children": [
    {
      "text": ""
    }
  ]
}