Authentication

When you make a REST API call, you must authenticate the user. The following provides an example of REST API authentication using Ajax.

Prerequisites

JavaScript Code Example

$.ajax({
  headers: {
    
    // To make cross-domain ajax calls. 
    // This is required if your front-end and back-end are in different domains.
    "Access-Control-Allow-Origin": "*",               
    
    // Supply your application name.
    appID: 'My Application', 
    
    // If your application is being served in multiple languages,
    // Call a method that returns the selected language id, for example (en-Us).
    locale: getLocale(),
    
    // Add implementation to obtain base64 encoded value of username and password. 
    Authorization: "Basic "+base64encode(UserName:Password)   
  
  },
  url: 'https://mydomain:9011/AgilePointServer/Admin/GetRegisterUser',
  
  // Pass username in JSON format {userName:'Domain\UserName'}
  data: JSON.stringify({ userName: 'demo3\lily.allen' }), 
  
  // default HTTP verb is post. 
  // If the verb is GET, you must specify it.
  type: 'POST',
  
  // Response content type. By default it is json.
  contentType: "application/json",                            
  
  // The default data type for the request body.
  dataType: "json",
  
  // Set async to true to make a non-blocking or asynchronous ajax call. 
  async: true,
  
  // Set cache to false to make sure we are not getting the cached response.
  cache: false,
  
  success: function (data, status) {
    try {
    
    // Handle success callbacks.
    } catch (e) {
           
    }
  },
  
  error: function (xhr, status, error) {
    try {
    
    //Handle any request error message or authentication failure messages.
    } catch (e) {
            
    }
  }
});