AnsweredAssumed Answered

finesse api returns status code of 200 instead of 202 and returns response only when the dataType dataType: "jsonp"

Question asked by hashmukh.punamia on May 27, 2015
Latest reply on May 29, 2015 by hashmukh.punamia

Hi All,

 

I am using finesse api to develop a thin client using jquery and jabber. When I make finesse api call, I get the success message with Status code as 200 and the response as xml.

Below is my code

 

/**
* Constructs and sends a request API (using jQuery). Since this sample JS
* and page is hosted outside of the Finesse Web Services server, making an
* Ajax request to that server will violate the same-origin policy. A common
* solution is to setup a HTTP proxy which will forward request to the
* Web Services server.
*
* @param {String} url
Where to send the request to.
* @param {String} method
*"GET", "POST", "PUT"
* @param {Map} headers
Object containing key/value header params.
* @param {Map} params
Object containing key/value params.
* @param {Function(Object)} handler
Callback to handle response.
* @param {Function(Object)} errHandler
Callback to handle error with request.
* @param {Boolean} cache
True if request should cache, false otherwise.
* @param {String} xml
The xml to pass to the request 
* @private
*/
_sendReq = function (
        url, method,
        headers, params,
        handler, errHandler,
        cache, xml) {
    var newUrl = url,
    delim = "?",
    param,
    p = p || {},
    xhrArgs;
  
      

 

  
    //Add BASIC credentials to be sent with each requests. The JSESSIONID
    //token should automatically be handled by the browser.
    if (_credentials) {
        headers = headers || {};
        headers.Authorization = "Basic " + _credentials;
    }
    xmlData = xml;
    
    //Request arguments.

    contentType = "application/xml";

  

    if (method === "GET") {

      xhrArgs = {

        url: newUrl,
        type: method,
        dataType: "jsonp",
        // contentType: contentType,
        accept : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    // added processData: false to not send data on url
    processData : false,
        beforeSend: _createSetHeader(headers),
        success: _createSuccessHandler(handler),
        error: _createErrorHandler(errHandler),
        cache: cache

      }

    } else {
      xhrArgs = {
        url: newUrl,
        type: method,
          dataType: "jsonp",
    //contentType: contentType,
    accept : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    data : xmlData,
    // added processData: false to not send data on url
    processData : false,
        beforeSend: _createSetHeader(headers),
        success: _createSuccessHandler(handler),
        error: _createErrorHandler(errHandler),
        cache: cache
   }
    };

 

    //Uses jQuery to send Ajax request to backend.
    jQuery.ajax(xhrArgs);
};

 

this.signIn = function (agentid, extension, forcedFlag, handler, errHandler) {
    // var method = "POST",
   var method = "PUT",
   cache = "",
    url = _webappPath + "/api/User/" + agentid;
    xmlData = "<User><state>LOGIN</state><extension>"+extension+"</extension></User>";
     //console.log(xmlData);
    _sendReq(url, method, null, null, handler, errHandler, null, xmlData);
};

 

I am able to get the response only when the dataType: "jsonp" (tested using firebug). The status code is 200 as oppose to 202 as per the documentation. Also I am not able to read the response in the the app.

 

I am using jquery 1.11.3, finesse 10.5.

 

Any help is appreciated

 

Thanks,

Hash

Outcomes