Invalid token provided error while making an ajax call Skip to main content
How satisfied are you with the Okta Help Center?
Thank you for your feedback!
How satisfied are you with the Okta Help Center?
Very Dissatisfied
Very satisfied
Enter content less than 200 characters.
Ask Search:
Bharat BhaskarBharat Bhaskar 

Invalid token provided error while making an ajax call

 I am getting Invalid token provided error . I created new token and with postman, I am able to create user but using ajax call I am not able to create user.Here is the sample code.
var express = require('express');
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');
var request = require('request');
var cookieParser = require('cookie-parser')
var port = process.env.port || 9002;
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
var router = express.Router();
app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
});'/createUser', function(req, res) {
    var oktaUserCreationData = {
        "profile": {
            "firstName": req.body.profile.firstName,
            "lastName": req.body.profile.lastName,
            "login": req.body.profile.webId + '~' +
    var usderData = JSON.stringify(oktaUserCreationData);
        url: "",
        method: "POST",
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Authorization': 'SSWS {{apiKey}}'
        json: true, // <--Very important!!!
        body: usderData
    }, function(error, response, body) {
        res.json({ "message": "Please check your mail and follow steps, to set your credential." })
app.use('/api', router);
app.listen(port, function() {
    console.log('Example app listening on port 9002!')

Here in the above code I am using my own apiToken. Can someone tell me what is te issue.
VictorVictor (Okta, Inc.) 
Hello Bharat Bhaskar!

Having a look at your code it seems the Okta API token is missing. You have declared for Authorization: SSWS{{apiKey}}, but is the token declared somewhere else than here?

I used the code provided by Postman for the {{url}}/api/v1/users?activate=false call and the token was declared as well. Here is an example provided from Postman for the same call you are using:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "yourOktaURL/api/v1/users?activate=false",
  "method": "POST",
  "headers": {
    "accept": "application/json",
    "content-type": "application/json",
    "authorization": "SSWS 00Token....xas.......",
    "cache-control": "no-cache",
    "postman-token": "70......."
  "processData": false,
  "data": "{\n  \"profile\": {\n    \"firstName\": \"Isaac\",\n    \"lastName\": \"Brock\",\n    \"email\": \"\",\n    \"login\": \"\"\n  }\n}"

$.ajax(settings).done(function (response) {

Please let us know if this steps helped you fix the issue!