How to call Bamboo HR API call from SharePoint Online - ajax

I would like to get data from Bamboo HR and display it in SharePoint Online. Bamboo HR supports API with basic authentication to call and get data from Bamboo HR. When I tried to get data in browser, it's working fine however when I use ajax call inside Script Editor Webpart in SharePoint, it gives me cross origin error. I also tried with jsonp using $.getJSON however it's also giving an error as below:
function test(a,b,c){debugger;
console.log(a);
}
$.ajax({
url:"https://api.bamboohr.com/api/gateway.php/test/v1/time_off/requests/?start=2018-04-25&end=2018-04-25&status=approved",
type: "GET",
headers: {
"accept": "application/json",
'Authorization': "Basic api_key:x")
},
dataType: 'jsonp',
jsonpCallback: 'test',
});
Above code throwing below error in SharePoint Online environment.
Refused to execute script from
'https://api.bamboohr.com/api/gateway.php/test/v1/time_off/requests/?start=2018-04-25&end=2018-04-25&status=approved&callback=test&_=1524995081404'
because its MIME type ('text/xml') is not executable, and strict MIME
type checking is enabled.
Any help to retrieve data from Bamboo HR into SharePoint will be appreciated.
Thanks in advance.

Here are two ways for your reference:
1.Pushing data to SharePoint list using RESTful service.
Create a job and push the data from Bamboo HR to SharePoint List using REST API of CSOM(C#).
2.Using Business Connectivity Service(BCS).
Manage Business Connectivity Service Applications

Related

How to call ajax from Excel JS API

I am new to Office.js API. I am trying to develop Web Add-In for Excel and I need to get data from WebAPI for this I am trying to use ajax but its not working
Here is very simple Ajax code
$.ajax({
url: "http://localhost:61721/api/values",
type: "GET",
dataType:"JSONP",
success: function (data) {
$("#div1").html(JSON.stringify(data));
},
error:function(error){}
});
Update
Is there any alternative way other than Ajax in Office.js through which we can get data from Web API?
From the client, AJAX requests must be send to SSL URIs and those URIs must be declared in AppDomain list of the app manifest. Please refer to: Send POST AJAX request from Office Add-In.
In the same time, if your app has server side portion of code, you may send direct request to any Web API from there. Nobody limit you in technology (REST, microservices, etc.) and nobody check your connection is secure, when using 3rd party resources from your server.

Send POST AJAX request from Office Add-In

I'm trying to send POST Ajax request for third party service from my Outlook Add-in, but no matter what I tried I receiving Error: Access is denied, and status 0 (request never hit the server).
Assuming we are running IE9 or 8 behind the outlook I tried old school hacks like https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest.
$.ajax({
url: endpoint,
data: JSON.stringify({'1':'2'}),
// headers: {'X-Requested-With': 'XMLHttpRequest'},
contentType: 'text/plain',
type: 'POST',
dataType: 'json',
error: function(xhr, status, error) {
// error
}
}).done(function(data) {
// done
});
Is there is something more I need to implement? Of cause I add my domain to manifest AppDomain property.
Cheers
The following needs to be done to send request to 3rd party service ...
Add the service URI to AppDomain list (you've done it.)
The service MUST have SSL endpoint; "https://your.domain" must be included within of "AppDomain" entry (see above)
The service has to allow CORS requests for your application (hosted Outlook App URI) domain or any domain. This is up to the service creators to allow or disallow client apps connections via Ajax.
As of observation of your code I notices you are sending JSON object, but setting content type to "text/plain". Contact the service creators to get information on what type of the data they accept as request. Usually services allow "application/json", but not plain text.

Invoking web service from Liferay portal using proxy

I'm trying to invoke web service from Liferay portal using proxy. I already managed to do so on IBM WebSphere portal, like this (invoking 'help'):
<portal_context_path>/proxy/http/<server_url>/<application_name>/help?lang=myLang&object=myObject
I'm making a call using ajax:
try {
$.ajax({
url: 'http://localhost:8080/LiferayTest-portlet/proxy/http/localhost:9081/ServiceApp/help?lang=myLang&object=myObject',
headers: {
'Accept': 'application/xml; charset=utf-8',
'Content-Type': 'application/xml; charset=utf-8'
},
success: function(xml) {
...
},
error: function(xhr, textStatus, errorThrown) {
...
}
});
} catch (e) {
...
}
The thing is, if I make that ajax call on Liferay portal, I get error (404 Not found), but if I call it from WebSphere portal (URL:http://localhost:10039/.WebSphereTest/proxy/http/localhost:9081/ServiceApp/help?lang=myLang&object=myObject), it works.
Is there a similar way (like using /proxy/http) to accomplish this on Liferay portal?
Is your application running inside of Liferay, and you're trying to call something outside, through a proxy? In that case accessing Web Services is just like anywhere else. Use the library of your choice to do this. Liferay does not provide a proxy for you - I don't see what that would bring to the table if it did.
Edit: If you want to access your portlet's "resource" phase, e.g. the request phase that is typically used for Ajax, you'll just have to obtain a resource-URL from Liferay. URL generation is the business of the underlying platform and well standardized. You seem to be using a Websphere-specific way. In a JSP you'd just use <portlet:resourceURL/> to obtain the URL that's handled in your portlet's resource-phase e.g. serveResource(...).
Yet another option is to deploy servlet-based web services with your portlet (as it's technically only a web application) but this is totally outside of the portlet realm and would have nothing to do with Liferay at all.
Ruled out in the comments, I'll still leave this paragraph in here: In case you want to consume Liferay's own API Web Services, they're available as JSON and SOAP. The SOAP services are available on localhost only, unless you configure them to be available to more hosts. Just like before, I don't see the point of an explicit, platform provided, proxy.

Ajax Post Error on Office Add-in from Outlook 2013

I have simple requirement here to fetch data from Exchange Online EWS API & SharePoint lists and display those data onto HTML page of Apps for Office. This office app should work on OWA (Web mail) as well as Outlook client. I was able to see the response data in browser (OWA - Web mail), but when I am trying to load the same add-in on outlook client it doesn't show the data and gives the error in errorMessage as:
No Transport
So, we did try enabling the CORS using $.support.cors = true as per this thread, but no luck with that and got Access Denied error.
Does anyone have found the solution for this kind of scenario. Any help would be much appreciated.
Below is code snippet where I am getting that error:
$.ajax({
url: "https://myazuretenant.azurewebsites.net/GetData.asmx/GetLocations",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// Data Manipulation goes here
},
error: function (data, errorCode, errorMessage) {
app.showNotification('Error: ' + errorCode + ' - ' + errorMessage);
}
});
Note: Ajax request is going through the generic Web API (ASMX Service), which fetches the data using ExchangeService library (EWS API) and SharePoint.

Why does my web service call fail when calling a different site

I am making a JQuery ajax call to a web service like so:
$.ajax({
type: "POST",
url: "https://WebsiteName.com/Service.asmx/LoginExternal",
data: "{loginData: " + JSON.stringify(LoginData) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
... Stuff ...
},
error: {
... Error Alert ...
}
});
When I am on the actual web site, this succeeds. When I am on localhost and use a relative path, it succeeds. However, when I am trying to access the web site (using an absolute path) from localhost, I get the error message that the call failed.
This would seem to indicate that it is a permissions problem and I've made sure that the web.config doesn't require authentication for access to the web service but I'm not sure what else to check. Any help would be greatly appreciated!
Update: The "thrownError" that I am getting is "No Transport" - hopefully that helps.
Security:
http://en.wikipedia.org/wiki/Same_origin_policy
Being an unsecured scripting logic, ajax requests made using JavaScript (or JQuery) are stucked on same host, protocol and port, due to unauthenticated and unencrypted requests.
A method for passing requests to a different host, you must implement a bridge service written in a secure language (ex. Java), deployed on same host that passes your requests further to your services, and then passes response to your ajax call.
Your ajax call will be on the bridge service then.

Resources