encountering a 404 error when making an $http post request

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 :

Answer №1

Experiment with:

result.resource_server_base_uri = unescape(query_string.resource_server_base_uri);

In actuality, / functions as a separator, whereas %2f transforms into an ordinary character that effectively represents the / character in your URL.

It's important to note that unescape() has been deprecated; hence, it is recommended to use decodeURIComponent() instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty passing a react component as an attribute to another component

I'm attempting to assign a React component as an attribute to another React component using Material UI like this: <Tabs> <Tab icon={<ActionFlightTakeoff />} /> </Tabs> However, when I inspect the browser, I see this: < ...

What is the fastest and most effective method for identifying the Angular or AngularJS version that a website is utilizing?

During my time at work, I have inherited a collection of over 30 web sites and applications that were created using C#, ASP.NET, MVC, and AngularJS/Angular. These projects were developed and updated between the years of 2010 to 2018, with some being more r ...

struggling to incorporate API Json response data into my HTML file using AngularJS

Below is the code I am currently using: angular.module('ngApp', []) .factory('authInterceptor', authInterceptor) .constant('API', 'http://myserver.com/app/api') .controller('task', taskData) function task ...

Error: The JSON ajax request encountered an unexpected number, resulting in an uncaught Syntax

My goal is to send a get request to a website and retrieve the response. Although I am able to successfully make the HTTP request and obtain a response, my code breaks due to a javascript error that keeps popping up. I suspect that the issue may be relat ...

Connecting a specific URL of an API to a single mobile app: A step-by-step guide

Currently, my API includes a user registration system that is utilized by a mobile application. Most of the URLs are restricted for anonymous users and require a token key for authorization, except for the register URL. The register URL needs to remain op ...

Can someone assist with deciphering this code?

I have come across some code and I am unsure of what language it is written in. How can I convert it to HTML? You can find the code here: http://pastebin.com/ePPXkhMP I need to make some edits to this code, but I am not sure how to go about converting it ...

Experiencing issues with HTTPS and AJAX in Laravel specifically on Safari and a handful of other browsers

I am encountering an error when making a post request using AJAX. The error message is as follows: PHP Parse error: syntax error, unexpected '/*' (T_STRING), expecting ')' in /home/laravel/public_html/public/index.php on line 47 PHP ...

Create allowances for specific areas

One of my methods involves the saving of an author using the .findOneAndUpdate function. The structure of AuthorInterface is as follows: export interface AuthorInterface { name: string, bio: string, githubLink: string, ...

Looped jQuery setTimeout not functioning correctly

I am facing an issue with processing a JSON file that contains a list of serialized objects. My goal is to walk through this JSON and display the messages from it one at a time, with a delay of 2 seconds between each message before ultimately stopping. I a ...

Navigating through choices in select element using webdriverio

Sample HTML: <select id="random_text"> <option value="option1">asadka_TEST</option> <option value="option2">Peter Parker</option> <option value="option3">Clark Kent</option> <option value="optio ...

Converting JSON data into an array of a particular type in Angular

My current challenge involves converting JSON data into an array of Recipe objects. Here is the response retrieved from the API: { "criteria": { "requirePictures": true, "q": null, "allowedIngredient": null, "excluded ...

Expanding upon the initial instance, the parent div effortlessly widens without any visual effects as the child element is revealed or concealed

Experiencing an issue where the div element opens and closes smoothly with jQuery animation, but its parent does not. As a result, the entire page content appears jerky. Here is a demo: http://jsfiddle.net/neDZP/7/ HTML: <div id="A_to_Z_top"> ...

Activating gzip compression using fetch.js

I am utilizing fetch.js (https://github.com/github/fetch) to transmit a rather substantial JSON object to the backend. The size of the JSON is significant due to it containing an SVG image string. My question is whether fetch.js applies gzip compression a ...

What is the best way to conceal a nested element if its parent's width is set to

I am attempting to dynamically hide a nested paragraph tag based on its parent's width. I want the nested p tag to adjust its visibility as the parent's width changes, either expanding or contracting. I believe there is a simple solution for this ...

Is it possible to make any object reactive within Vuex?

Seeking ways to enhance the sorting of normalized objects based on a relationship. Imagine having an application that requires organizing data in a Vuex store containing multiple normalized objects, like this: state: { worms: { 3: { id: 3, na ...

Aligning dynamically-sized TextInput in React Native

I am facing a challenge in centering a text input with a width that matches the length of the input text. I have tried using alignSelf: 'center' and alignItems: 'center', but the text input is not visible without specifying a width. Fo ...

Struggling to integrate Material UI (MUI) into my React application

I have followed all the necessary steps to install materialUI, emotion/react, and emotion/styled in my react app. However, I am encountering an issue where MUI does not seem to work properly. There are no errors displayed on the console or webpage, but not ...

Error: jwt_decode function has not been declared

I'm currently working on a project and I've hit a roadblock while trying to fetch profile information for the logged-in account using a token. Despite using the JWT-decoding library, I keep encountering the issue where jwt_decode is not defined. ...

Is there a way to accurately retrieve the width of an element within setInterval without any delay?

I'm currently experimenting with increasing a progress bar using the setInterval function. So far, it seems to be functioning properly. var progressBar = $('.progress-bar'); var count = 0; var interval = setInterval(function () { va ...

Verify the dialog box return with a text input box

I am trying to implement a confirmation dialog box for when a user wants to delete their account. This dialog box requires the user to enter their password in a textbox. However, I am struggling with catching the postback event and executing the relevant m ...