$.ajax({
url: "https://mycompany.nexus.support.com/api/v1/oauth2/token",
type: 'POST',
dataType: 'json',
data: client,
success: function(result) {
var accesstoken = result.access_token;
$.ajax({
url: 'https://mycompany.nexus.support.com/api/v1/sessions/search',
type: 'POST',
dataType: 'json',
data: search_session, // or $('#myform').serializeArray()
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Bearer " + accesstoken);
},
success: function(data) {
var session_id = data[0].id;
var session_user = {"email":user_email};
var update_data = {"user":session_user};
$.ajax({
url: 'https://mycompany.nexus.support.com/api/v1/sessions/'+session_id,
type: 'PUT',
dataType: 'json',
data: update_data, // or $('#myform').serializeArray()
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Bearer " + accesstoken);
},
success: function(result) {
console.log('result',result);
}
});
}
});
}
});