BEAR API utilizes Basic Authentication to authenticate a caller. Authentication Header should be sent with each call to the API. So there is no Login / Logout API calls.
Usage (working example here):
getUsers ();
function getUsers () {
var user = 'user';
var password = 'test';
var auth = "Basic " + btoa(user + ":" + password);
var urlApi = 'https://api.bear2b.com/users';
$.ajax({
processData: true,
type: 'GET',
url: urlApi,
headers: {"Authorization": auth},
success: function(data){
var user = data[0];
$('body').html(user.display_name);
},
error: function(data){
$('body').html( data.responseJSON.error + ' ' + data.responseJSON.description );
}
});
}
You can also set Authentication header for all ajax calls using this code snippet:
var user = 'user';
var password = 'test';
var auth = "Basic " + btoa(user + ":" + password);
$.ajaxSetup({ headers: {"Authorization": auth} });
Commentaires
Vous devez vous connecter pour laisser un commentaire.