csMgmtApp.controller('launchedController', ['$scope', '$http', '$document', '$resource', function ($scope, $http, $document, $resource) {
$scope.clientResult = {};
$scope.data = {};
$document.ready(function () {
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0; i < vars.length; i++) {
var pair = vars[i].split("=");
query_string[pair[0]] = pair[1];
}
if (typeof(query_string.access_token) != "undefined") {
var result = {};
result.state = query_string.state;
result.scope = query_string.scope;
result.access_token = query_string.access_token;
result.expires_in = query_string.expires_in;
result.resource_server_base_uri = query_string.resource_server_base_uri;
result.token_type = query_string.token_type;
}
$scope.clientResult = result;
});
console.log($scope.clientResult);
$scope.startSessionPayload = {
'stationPhoneNumber': '5555555555',
'inactivityTimeout': '0',
'inactivityForceLogout': 'false'
};
$http({
'url': $scope.clientResult.resource_server_base_uri + 'services/v6.0/agent-sessions',
'method': 'POST',
'headers':{'Authorization': 'bearer ' + $scope.clientResult.access_token,'content-Type': 'application/json'},
'data': JSON.stringify($scope.startSessionPayload)
}).success(function(data, status, headers, config) {
$scope.data = data;
console.log('data', $scope.data)
}).error(function(data, status, headers, config) {
$scope.status = status;
});
}]);
The above script results in a 404 error when attempting the $http "POST" request.
On using console.log($scope.clientResult.resource_server_base_uri), the output is: "https%3a%2f%2fapi-c7.incontact.com%2finContactAPI%2f".
However, I encounter a 404 error and upon inspecting developer tools, I notice that it's trying to post to :
"http://localhost:63342/Call_cntr/client/https%3a%2f%2fapi-c7.incontact.com%2finContactAPI%2fservices/v6.0/agent-sessions"
I suspect the failure is due to the "://localhost..." being prepended to the base_uri... I am unsure of why this is happening. It seems like all necessary information is provided as per the inContact API docs. Is there possibly an issue with my angular conversion from AJAX to $http ??
Your assistance would be greatly appreciated as I'm currently stuck..
After obtaining an API Authentication Token, you can utilize this token to establish an agent session for the agent associated with the credentials used to acquire the token. This can be achieved by requesting the {cluster}.incontact.com/inContactAPI/services/v6.0/agent-sessions method and providing either a "station ID" or a phone number which will be assigned to the agent.
As per the documentation :