In my factory, everything was running smoothly with regular ajax syntax from the controller.
function endAgentSession(sessionData, tokenData) {
var sessionId = sessionData.data.sessionId,
access_token = tokenData.access_token,
baseURI = tokenData.resource_server_base_uri,
endAgentSessionPayload = {
'sessionId': sessionId,
'forceLogOff': true,
'endContacts': true,
'ignorePersonalQueue': false
};
console.log(sessionId, "sessID");
return $http({
'url': baseURI + 'services/v6.0/agent-sessions/' + sessionId,
'type': 'DELETE',
'headers': {
//Use access_token previously retrieved from inContact token service
'Authorization': 'bearer ' + access_token,
'content-Type': 'application/json'
},
'data': endAgentSessionPayload
}).then(function(res){
return res })};
}
A 405 error occurs when I call the endAgentSession function from the controller using an ng-click.
$scope.endAgentSession = function(){
agentFactory.endAgentSession($scope.sessionData, $scope.tokenData);
};
Something seems to have gone wrong. It was functioning properly with ajax in the controller, but when moved to the factory and utilized a promise, it breaks down.
Interestingly, it shows that it's requesting a GET request in Network.. [![enter image description here][1]][1]
Here is the full controller:
csMgmtApp.controller('launchedController', ['$scope', '$http', '$document', '$resource', 'agentFactory', '$timeout', function ($scope, $http, $document, $resource, agentFactory, $timeout) {
$scope.agentStatePayload = {};
$scope.sessionData = {};
$scope.tokenData = {};
$scope.startSessionPayload = {
'stationPhoneNumber': '2223222222',
'inactivityTimeout': 0,
'inactivityForceLogout': 'false'
};
$document.ready(function () {
$scope.tokenData = agentFactory.getToken();
console.log($scope.tokenData);
});
agentFactory.startSession($scope.startSessionPayload, $scope.tokenData).then(function(res){
console.log("sessionId", res);
$scope.sessionData = res;
});
$scope.endAgentSession = function(){
agentFactory.endAgentSession($scope.sessionData, $scope.tokenData);
};
}]);
Everything appears to be functioning correctly, except for the endSession now..