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 code above gives me a 404 when I try te $http "POST".
When I console.log($scope.clientResult.resource_server_base_uri), I get: "https%3a%2f%2fapi-c7.incontact.com%2finContactAPI%2f".
But, I get a 404, and when I look in developer tools, I see 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'm starting to think it's failing because the "://localhost..." is being "prepended" to the base_uri... Not sure why this is happening. I feel I'm providing everything mentioned in the inContact API docs. Maybe it's with my angular conversion from AJAX to $http ??
Any help, much appreciated, I'm stuck..
Once you have an API Authentication Token, you use this token to create an agent session for the agent whose credentials you used to get the token. This is done by requesting the https://api-{cluster}.incontact.com/inContactAPI/services/v6.0/agent-sessions method, and supplying either a "station ID" or a phone number which will be delivered to the agent.
per the docs : https://developer.incontact.com/API/AgentAPI#!/Sessions/startSession