cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
396
Views
5
Helpful
8
Replies
Beginner

Finesse Gadget API failures

Making a gadget that makes a REST API call to an endpoint using the POST method. The initial call succeeds, however, it then seems to call some other function to refresh the gadget pane. This secondary call (makeXhrRequest()) tries to place params that I'm setting in the initial POST call into a finesse URL, which causes a "Missing or Malformed URL" error.

My custom functions are below, but it seems there is some secondary function call built into gadgets.io.makeRequest. I don't have further information right now. Is anyone familiar with gadgets.io.makeRequest?

 

postMetadata : function (loanIDManual, ct1, ct2, ct3, notes) {

var url = "http://<customEndpoint>/";
var loginName = user.getData().loginName;

clientLogs.log("loanIDManual = " + loanIDManual);
clientLogs.log("ct1 = " + ct1);
clientLogs.log("ct2 = " + ct2);
clientLogs.log("ct3 = " + ct3);
var contentBody = {
"acdServerId": "6",
"loginName": loginName,
"metadata": [
{
"name": "LoanIDManual",
"value": loanIDManual
},
{
"name": "call-outcome-l-1-key",
"value": ct1
},
{
"name": "call-outcome-l-2-key",
"value": ct2
},
{
"name": "call-outcome-l-3-key",
"value": ct3
},
{
"name":"notes-key",
"value": notes
}
]
};

clientLogs.log("Posting metadata to " + url);
clientLogs.log("Using " + contentBody);

 

makeRequest(url, {
method: 'POST',
contentType: "application/json",
content: JSON.stringify(contentBody, null, 4),
}, {
success: handleResponseSuccess,
error: handleResponseError,
});
clientLogs.log("postMetadata() complete.");
},

 

 

 

makeRequest = function (url, options, handlers) {
var params,
clientLogs.log("makeRequest()");
clientLogs.log("Header = " + options.contentType);

// Protect against null de-referencing of options & handlers allowing its (nonexistent) keys to be read as undefined
params = {};
options = options || {};
handlers.success = _util.validateHandler(handlers.success);
handlers.error = _util.validateHandler(handlers.error);

// Request Headers
params[gadgets.io.RequestParameters.HEADERS] = {"CUSTOM-KEY":"ROLE_USER"}
params[gadgets.io.RequestParameters.HEADERS] = {"Content-Type":"application/json"};

// HTTP method is a passthrough to gadgets.io.makeRequest
params[gadgets.io.RequestParameters.METHOD] = options.method;

 


if (options.method === "GET") {
// Disable caching for GETs
if (url.indexOf("?") > -1) {
url += "&";
} else {
url += "?";
}
url += "nocache=" + _util.currentTimeMillis();
}

// Add content type & body if content body is provided
if (options.content) {

// Content

params[gadgets.io.RequestParameters.POST_DATA] = options.content;

}

// Call the gadgets.io.makerequest function with the encoded url
clientLogs.log("makeRequest(): Making a REST API request to: " + url);
gadgets.io.makeRequest(encodeURI(url), handleResponse(handlers), params);
clientLogs.log("makeRequest() complete.");
},

Everyone's tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Beginner

Re: Finesse Gadget API failures

Denise,

I got this sorted out. I am no kind of html dev, so forgive my dodgy explanation here:

 

I added type=button to my submit button, and that fixed the issue. Seems like without the button "type" information, Finesse wasn't sure what to do, and tried to use a sort of default behavior, which was the problem I described earlier.

8 REPLIES 8
Enthusiast

Re: Finesse Gadget API failures

Can you do a capture on the outgoing URL to see what the exact url it's trying looks like?

 

My makeRequest looks like this:

gadgets.io.makeRequest(encodeURI(url), handleResponse(handlers), params);
Beginner

Re: Finesse Gadget API failures

Quigath,

Sorry for the delay here, been a bit crazy. My makeRequest is identical to yours. The outgoing URL is fine, insofar as the request I'm trying to make succeeds, it's just that it seems the gadget tries to refresh by fetching from a URL the does not exist. Here is some more information:

 

makeRequest Headers tab:
url: http://<EndPoint Address>:8080/api/cc-admin/v1/recordingcontrols/metadata
httpMethod: POST
headers: Content-Type=application%2Fjson&ShindigAuthorization=Basic%20MzAwMzAwMzg5NTphYmNkMTIzNA%3D%3D
postData: {
"acdServerId": "6",
"loginName": "cscoloansales",
"metadata": [
{
"name": "LoanIDManual",
"value": "23"
},
{
"name": "call-outcome-l-1-key",
"value": "Prelist"
},
{
"name": "call-outcome-l-2-key",
"value": "How it works"
},
{
"name": "call-outcome-l-3-key",
"value": "Safety/Privacy"
},
{
"name": "notes-key",
"value": "testtest"
}
]
}

 

Next line in network logs;
Request URL: https://<Finesse Server>:8445/gadgets/ifr?loanIDManual=23&ct1=Prelist&ct2=How+it+works&ct3=Safety%2FPrivacy&loanIDManual=testtest
Request Method: GET

 

Notice above that Finesse is taking the parameters from the body of my makeRequest, and putting them into a Finesse URL, then trying to get something from the URL it just made up.

 

 

Beginner

Re: Finesse Gadget API failures

For good measure, here is the form and function call from the xml:

 

<div id="dialog-confirm" title=titleStr>
<form id="catForm" onload="init_CT1('MS');" " method="POST">
<table width="500px" columns="2" margin="2px" border="0">
<tr>
<td><input name="loanIDManual" id="loanIDManual" type="text" placeholder="LoanIDManual" /td>
<td align="right"> Case Type:</td>
<td><select name="ct1" id="ct1" onChange="changect2(this.value);" >
<option value="" disabled selected>Select</option>
</select></td>
<td align="right">Sub Type:</td>
<td> <select name="ct2" id="ct2" onChange="changect3(this.value);">
<option value="" disabled selected>Select</option>
</select> </td>
<td> <select name="ct3" id="ct3";">
<option value="" disabled selected>Select</option>
</select> <br>
<div id="ct3sample"></div>
</td>
<td><input name="loanIDManual" id="notes" type="text" placeholder="Notes" /td>
</tr>
<tr>
<button onclick="finesse.modules.calltype.postMetadata(document.getElementById('loanIDManual').value,document.getElementById('ct1').value,document.getElementById('ct2').value,document.getElementById('ct3').value,document.getElementById('notes').value)">Submit</button>

</tr>
</table>

Cisco Employee

Re: Finesse Gadget API failures

Strange. I haven't seen this before. Is it possible to see if this is reproducible with a different REST API?

 

Thanx,

Denise

Beginner

Re: Finesse Gadget API failures

Denise,

I got this sorted out. I am no kind of html dev, so forgive my dodgy explanation here:

 

I added type=button to my submit button, and that fixed the issue. Seems like without the button "type" information, Finesse wasn't sure what to do, and tried to use a sort of default behavior, which was the problem I described earlier.

Beginner

Re: Finesse Gadget API failures

Hi,

We're facing similar issue (pls see https://community.cisco.com/t5/contact-center/jquery-event-handlers-in-finesse-gadgets/m-p/3840053/highlight/true#M9809 for simplest possible gadget we re-procuded the issue with). I first though it was related to jQuery event handler, but we have also re-produced it without single line of jQuery. 

And in our case, the gadget code does it's job, but right after that, the browser calls that https://xxx.xxx.xxx.xxx/gadgets/ifr? URL and that call fails with HTTP 400 and error message is rendered in the gadget,

Beginner

Re: Finesse Gadget API failures

Sorry, missed the comment on adding "type=button" above. I added that definition to my button element as well and indeed, the solved the issue ... cannot figure out why though.

Cisco Employee

Re: Finesse Gadget API failures

Hi,

 

The code that you pasted looks correct for the make request. I agree that you should try to figure out what is the "Missing or Malformed URL". The gadget typically doesn't refresh on its own so could it be that your code is having the gadget refresh? Maybe it is calling a URL that shouldn't be called?

 

You'd have to dig deeper using the browser developer's tool to figure out what is wrong.

 

Thanx,

Denise

CreatePlease to create content
Content for Community-Ad
August's Community Spotlight Awards