Skip to content

Instantly share code, notes, and snippets.

@brianwmunz
brianwmunz / authenticate.js
Last active Nov 5, 2021
Authenticate your expert.ai NL API connection and set a variable with the bearer token in node.js / javascript
View authenticate.js
var uname = "username@faketest.com";
var pass = "fakePassword";
// Get a token from the NL API by creating a promise that retrieves the token when needed.
const token = new Promise((resolve, reject) => { //we're setting the variable 'token' to the value that is returned
var jsonBody = { "username": uname, "password": pass };
fetch("https://developer.expert.ai/oauth2/token", { //send the username and password to the auth endpoint
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8"