---
title: Get JWT token to authenticate all requests.
slug: feature-experimentation/api/get-jwt-token-to-authenticate-all-requests
docTags: 
createdAt: 2026-08-28T15:54:06.731Z
---

{
  "id": "n8TWQn1-fAlKHqtLxz16O",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "/oauth/token",
    "servers": [],
    "name": "Get JWT token to authenticate all requests.",
    "description": "<p>Generates valid JWT token for grant_type, client_id, and client_secret, using the values you pass in the request body.  Configure expiration time and SDK keys (to which the token grants access) in Optimizely config.</p>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        }
      ],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "required",
          "name": "body",
          "type": "object",
          "description": "",
          "customType": "TokenContext",
          "schema": [
            {
              "name": "grant_type",
              "kind": "optional",
              "type": "string",
              "description": ""
            },
            {
              "name": "client_id",
              "kind": "optional",
              "type": "string",
              "description": ""
            },
            {
              "name": "client_secret",
              "kind": "optional",
              "type": "string",
              "description": ""
            }
          ],
          "modelRef": "#/components/schemas/TokenContext",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "SdkKeyAuth",
          "name": "X-Optimizely-SDK-Key",
          "kind": "optional",
          "type": "apiKey",
          "in": "header"
        },
        {
          "id": "TokenAuth",
          "name": "TokenAuth",
          "kind": "optional",
          "type": "http",
          "scheme": "bearer"
        }
      ],
      "cookieParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "Generates a valid token",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "401",
        "description": "Unable to match credentials",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "TokenError",
            "schema": [
              {
                "name": "error",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "error_description",
                "kind": "optional",
                "type": "string",
                "description": ""
              }
            ],
            "modelRef": "#/components/schemas/TokenError",
            "isExpanded": true
          }
        ]
      }
    ],
    "hasXCodeSamples": false,
    "deprecated": false,
    "examples": {
      "languages": [
        {
          "id": "VItty6SPeXJvhpweqoy9A",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url /oauth/token \\\n     --header 'accept: application/json'"
        },
        {
          "id": "cEavdPJN10UfC6wxqJ2cQ",
          "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(\"/oauth/token\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "TiYXtMF0osTUXfKJ8YAmQ",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"/oauth/token\")\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": "vtZ7QSF7TOFcHW3wLtSkE",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"/oauth/token\"\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": "VItty6SPeXJvhpweqoy9A"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Generates a valid token\n"
        },
        {
          "id": "response-1-401",
          "language": "401",
          "code": "// Unable to match credentials\n{\n  \"error\": \"\",\n  \"error_description\": \"\"\n}"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}