1. Home
  2. API
  3. Authentication

Authentication

BEAR API utilize Basic Authentication to authenticate a caller. Authentication Header should be send with each call to the API. So there is no any 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} });
Was this article helpful to you? Yes No

How can we help?