4

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

yanik
  • 798
  • 11
  • 33

1 Answers1

7

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.

Slava Ivanov
  • 6,666
  • 2
  • 23
  • 34
  • 1
    One additional point worth noting, Outlook for Windows is using IE11 but add-ins run across platforms so it isn't safe to assume which browser/engine your users are running. – Marc LaFleur Jul 25 '17 at 16:46
  • @SlavaIvanov, Is there any minimum `Mailbox` requirements set to do these request? Cause https://dev.office.com/reference/add-ins/outlook/1.5/index says that calling REST API has been introduced in 1.5 (?) – Niko Jul 07 '18 at 13:40
  • 1
    @Niko The documentation is talking about Exchange (Outlook) REST API, which was introduced at the certain API level. The original question was regarding the connection to 3rd party REST service, which doesn't have any limitation on Office.js API level and 1.0 is totally fine. Best regards. – Slava Ivanov Jul 12 '18 at 18:23
  • Is the SSL requirement mentioned anywhere in the official documentation? and in this case, is it a requirement only for POST requests?, because I am able to send only get requests to my non-SSL service. – Yazid Erman Dec 25 '18 at 05:47
  • @YazidErman Yes, SSL is the requirement for Outlook Add-ins. Please see [Privacy and security for Office Add-ins](https://learn.microsoft.com/en-us/office/dev/add-ins/concepts/privacy-and-security) document. – Slava Ivanov Jan 04 '19 at 21:38
  • @SlavaIvanov How can I set up a ssl for localhost? Self signed certificate is not working. Can you please give me any hints ? – Md. Mahmud Hasan Apr 24 '19 at 06:23
  • @Md.MahmudHasan [Self-signed certificates are perfectly fine for development and testing](https://learn.microsoft.com/en-us/office/dev/add-ins/quickstarts/project-quickstart#start-the-dev-server). There are a lot of resources which describes how to set up SSL certificate on local server. To provide any hints I would need to know at least the server you are using. Usually it's IIS Express, but many ppl use IIS as well. Anyway this is not the scope of the original question. You better post your own thread for specific question and full explanation what you have tried and what failed. – Slava Ivanov Apr 24 '19 at 13:13