is it possible to use gadget.io.makerequest to the external Rest API?
API to Call: https://reqres.in/api/users/2
I am trying to call the API above using gadget.io.makerequest . I am getting error while calling it.
here is my code.
------------------------
prepareRestRequest = function () {
// Call the REST API and display the results
var url = "https://reqres.in/api/users/2";
makeRequest(url, {
method: 'GET',
authorization: _util.getAuthHeaderString(finesse.gadget.Config),
contentType: 'application/xml'
}, {
success: handleResponseSuccess,
error: handleResponseError
});
},
------------------------
makeRequest = function (url, options, handlers) {
var params, uuid;
var funcName = "makeRequest()";
logMessage(funcName, 'Inside');
// Protect against null dereferencing of options & handlers allowing its (nonexistant) 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] = {};
// 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();
} else {
// Generate a requestID and add it to the headers
uuid = _util.generateUUID();
params[gadgets.io.RequestParameters.HEADERS].requestId = uuid;
params[gadgets.io.RequestParameters.GET_FULL_HEADERS] = "true";
}
// Add authorization to the request header if provided
if(options.authorization) {
params[gadgets.io.RequestParameters.HEADERS].Authorization = options.authorization;
}
// Add content type & body if content body is provided
if (options.content) {
// Content Type
params[gadgets.io.RequestParameters.HEADERS]["Content-Type"] = options.contentType;
// Content
params[gadgets.io.RequestParameters.POST_DATA] = options.content;
}
// Call the gadgets.io.makereqest function with the encoded url
logMessage(funcName, "Making a REST API request to: " + url);
gadgets.io.makeRequest(encodeURI(url), handleResponse(handlers), params);
logMessage(funcName, 'Getting Out');
},
-------------------------------------
I have attached the error screen shot here.