Follow

Authentication

BEAR API needs Basic Authentication to authenticate caller. Authentication header should be sent with every call made to the API. So there is no Login / Logout API call.

 

Following code example is written in JavaScript with jQuery :

getUsers (); 

function getUsers () {

   var user = 'user';

   var password = 'test';

   var auth = "Basic " + btoa(user + ":" + password);

   var urlApi = 'https://apidev.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 by using this code snippet :

var user = 'user';

var password = 'test';

var auth = "Basic " + btoa(user + ":" + password);

$.ajaxSetup({ headers: {"Authorization": auth} });

0 Comments

Please sign in to leave a comment.