Using basic authentication Instead of sending account details as body parameters, you can use basic authentication to generate a bearer token instead.
Before calling other endpoints, you need to generate an Authorization Bearer token. To retrieve your token using basic auth, simply send your account credentials in base64 encoded format within the header.
The format should be Basic email:password where email:password are encoded.
Generate a bearer token using basic authentication
POST
/api-basic-auth
Generate a token for use with other endpoints.
Request
cURL Node.js Javascript Ruby Python
Copy curl --location 'https://enterprise.personr.co/api/1.1/wf/api-basic-auth' \
-H "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ="
Copy const axios = require ( 'axios' );
const base64 = require ( 'base-64' );
const email = 'example@personr.co' ;
const password = 'example123' ;
const credentials = base64 .encode ( ` ${ email } : ${ password } ` );
const config = {
headers : {
'Authorization' : `Basic ${ credentials } `
}
};
axios .get ( 'https://enterprise.personr.co/api/1.1/wf/api-basic-auth' , config)
.then (response => {
console .log ( 'Response:' , response .data);
})
.catch (error => {
console .error ( 'Error:' , error);
});
Copy const email = 'example@personr.co' ;
const password = 'example123' ;
const credentials = btoa ( ` ${ email } : ${ password } ` );
const headers = new Headers ();
headers .append ( 'Authorization' , `Basic ${ credentials } ` );
headers .append ( 'Content-Type' , 'application/json' );
fetch ( 'https://enterprise.personr.co/api/1.1/wf/api-basic-auth' , {
method : 'POST' ,
headers : headers
})
.then (response => response .json ())
.then (data => {
console .log ( 'Response:' , data);
})
.catch (error => {
console .error ( 'Error:' , error);
});
Copy require "uri"
require "net/http"
require "base64"
email = "example@personr.co"
password = "example123"
credentials = Base64 . strict_encode64( " #{email} : #{password} " )
url = URI ( "https://enterprise.personr.co/api/1.1/wf/api-basic-auth" )
https = Net :: HTTP . new (url . host , url . port)
https . use_ssl = true
request = Net :: HTTP :: Post . new (url)
request[ "Authorization" ] = "Basic #{credentials} "
response = https . request(request)
puts response . read_body
Copy import requests
import base64
email = 'example@personr.co'
password = 'example123'
credentials = base64 . b64encode ( f ' { email } : { password } ' . encode ()). decode ()
url = "https://enterprise.personr.co/api/1.1/wf/api-basic-auth"
headers = {
'Authorization' : f 'Basic { credentials } '
}
response = requests . post (url, headers = headers)
print (response.text)
Response
200 400
Copy {
"status" : "success" ,
"response" : {
"token" : "1670035114445x631333625381113500" ,
"user_id" : "1665086295388x405886519539808060" ,
"expires" : 31536000
}
}
Copy {
"statusCode" : 400 ,
"reason" : "INVALID_LOGIN_CREDENTIALS" ,
"message" : "We didn’t find an account with those login credentials" ,
}
In the response, you'll receive:
The expiration time of your token, expressed in seconds
Remember to include your token in the header of every subsequent API call, in the format Authorization: Bearer YOUR_TOKEN
Don't forget to set up a workflow to renew your token before it expires.
Last updated 4 months ago