How to Use Office 365 api in Provider Hosted App

Hi,
I want to use outlook api in SharePoint Provider Hosted App.
when I use :-
 $.ajax({
            url: 'https://outlook.office365.com/api/v1.0/me/contacts',
            type: 'GET',
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'Bearer');
            Accept: "application/json",
            "client-request-id": "9de3d763-a8d9-4433-92f3-096d6be36d86",
            success: function () {
            alert("Welcome to Outlook ")},
            error: function (e) {
                alert(' Error121212 :' +e);
Error:-
XMLHttpRequest cannot load https://outlook.office365.com/api/v1.0/me/contacts. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:44309' is therefore not allowed access. The response had HTTP status code
401.
Please Provide me a good example.
Thanks in Advance

Hi SharePlus,
You probably want to use the Office 365 API's to authenticate and communicate with the API's. 
There's several resources available for this:
Ultimate LinkRoll for Getting Started with the Office 365 API's
Download Office 365 API Tools for Visual Studio 2013
Getting Started with O365 Dev - Communicate with Exchange
If you don't want to use the pre-compiled typed objects in the Office 365 API's for communicating with the Mail service (Exchange), you can always just make sure to handle the authentication properly and then construct your queries as raw queries, like Chaks
describes here: http://chakkaradeep.com/index.php/working-with-office365apis-the-raw-version/
Also, as a general rule; When working with anything Office 365, you should always keep an eye out for the example code, articles and news published from the Office 365 Patterns & Practices team here: https://github.com/OfficeDev/PnP
I hope this will guide you in the right direction :-)
Tobias Zimmergren
Microsoft MCP, MCTS, MCT, MVP (SharePoint)
Blog: www.zimmergren.net
Twitter: twitter.com/zimmergren
Corporate site: www.tozit.com

Similar Messages

  • Sharepoint provider hosted app using angularjs

    I am working on a provider hosted app and trying to access the list item through REST call using angularjs. But I am not able to access the list. Is it possible to access the sharepoint list through REST call using angularjs in a provider hosted app?
    Below is the code for angular:
    var hostWebApp = angular.module('HostWebList', []);
    Service:
    hostWebApp.service('$SharePointJSOMService', function ($q, $http) {
        this.getListItems = function ($scope, listTitle) {
            var deferred = $q.defer();
            //First we must call the EnsureSetup method
            JSRequest.EnsureSetup();
            var hostweburl = decodeURIComponent(JSRequest.QueryString["SPHostUrl"]);
            var appweburl = decodeURIComponent(JSRequest.QueryString["SPAppWebUrl"]);
            var restQueryUrl = hostweburl + "/_api/web/lists/getbytitle('ListName')/items";
            var executor = new SP.RequestExecutor(hostweburl);
            executor.executeAsync({
                url: restQueryUrl,
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: function (data, textStatus, xhr) {
                    deferred.resolve(JSON.parse(data.body));
                error: function (xhr, textStatus, errorThrown) {
                    alert("request failed");
                    alert(textStatus);
    //getting -1003
                    alert(JSON.stringify(xhr));
    //{"responseAvailable":false,"body":,"Header":null}
                    deferred.reject(JSON.stringify(xhr));
            return deferred.promise;
    Controller:
    hostWebApp.controller('HostWebListController', function ($scope, $SharePointJSOMService) {
        $scope.listItem = null;
        var listName = "IncomingEmail";
        var promise = $SharePointJSOMService.getListItems($scope, listName);
        promise.then(function (data) {
            $scope.listItem = data.d.results;
            alert($scope.listItem);
            console.log("came inside the promise success method");
        }, function (data) {
            console.log("Error " + data);
    Following javascript files I have included:
     <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
      <script type="text/javascript" src="/_layouts/15/sp.js"></script>
     <script type="text/javascript" src="/_layouts/15/SP.RequestExecutor.js"></script>
     <script type="text/javascript" src="/_layouts/15/init.debug.js"></script>
    angular.js included. 
    I don't know what is the problem. Can anybody walk me through the problem. will be great help.

    Your REST request must be authenticated. So you must send the access token in the authorization header along with your request. The following link explains how you can get the access token when you using a provider hosted app.
    http://blog.mastykarz.nl/using-sharepoint-rest-api-in-provider-hosted-apps/
    Blog | SharePoint Field Notes Dev Tools |
    SPFastDeploy | SPRemoteAPIExplorer

  • How to get the current user name in Provider hosted app using appOnlyAccessToken

    Hi, 
    Please help me, how to get the HostWeb UserName in Provider Hosted App
    i have Provider hosted App, and Anonymous Authentication is enabled on AppWeb, using appOnlyAccessToken
    Below code does not return current user who Log in in hostweb, it is returning
    SharePoint App (app@sharepoint)
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    clientContext.Load(web.CurrentUser);
    clientContext.ExecuteQuery();
    clientContext.Web.CurrentUser.LoginName;
    Below code gives a blank name when Anonymous Authentication is enabled, if Anonymous Authentication is disabled
    app prompts for credentials 
    HttpContext.Current.User.Identity.Name
    Thanks
    Ram

    Hi,
    Since you are using a provider Hosted app if you want to get the current logged in name than do not use AppOnlyAccessToken else use AccessToken which is App + user Context AccessToken.
    then 
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    clientContext.Load(web.CurrentUser);
    clientContext.ExecuteQuery();
    clientContext.Web.CurrentUser.LoginName;will return proper user Name.
    HttpContext.Current.User.Identity.Name will never return the user as this object is related to IIS server of your App Server not sharepoint.you should set this as Anonymous in case of provider hosted app.you can download the below sample which uses the AccessToken which has user name in it.https://code.msdn.microsoft.com/Working-provider-hosted-8fdf2d95
    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

  • How to get sharepoint online (office 365) data in cloud/windows azure (provider) hosted app using Javascript?

    How to get sharepoint online (office 365) data in cloud/windows azure (provider) hosted app using Javascript?
    I wish to retrieve sharepoint online data in html page (hosted in windows azure) using javascript and then need to play with AngularJS

    Hi,
    According to your description, you might want to get data from Office 365 SharePoint Online(also known as host web) and pass to the Provider Hosted App which is hosted
    in Windows Azure site.
    I would suggest you take a look at the links below about accessing data from the host web
     for a quick start:
    https://msdn.microsoft.com/en-us/library/office/fp179927(v=office.15).aspx#SP15Accessdatafromremoteapp_Codeexample
    http://dannyjessee.com/blog/index.php/2014/07/accessing-sharepoint-data-from-provider-hosted-apps-use-the-right-context/
    Aother sample solution for your reference:
    https://code.msdn.microsoft.com/SharePoint-2013-Get-the-0ec36bb6
    Best regards
    Patrick Liang
    TechNet Community Support

  • Can a faculty of an educational institute in India purchase, install, and use 'Office 365 University' in computers (desktops or laptops) provided by the Institute or University?

    Can a faculty of an educational institute in India purchase, install, and use 'Office 365 University' in computers (desktops or laptops) provided by the Institute or University?

    This may be of use: Education software licensing | Adobe Buying Programs.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • Using Office 365 - how to close sub folders in iPhone-mail app.

    using Office 365 - how to close sub folders in iPhone-mail app.

    Isn't HotMail still POP3 mail only (i.e. no IMAP support)?  If that is still the case, then your device is working correctly.  The folders you made are a feature of the web tool for hotmail, and are not part of the POP3 supported email protocol.  Only IMAP mail supports on-server mail subfolders, and those can be accessed from the iPhone mail client.  But POP3 is limited to the inbox solely, as that is literally the only folder that sits on the mail server (your others are on Microsofts web server and supported via the web mail tool).

  • Javascript Support in Office 365 APIs

    Looking at the Office 365 API Preview, I came across this sentence in the Discovery Service section.
    "Currently, the Discovery Service APIs are available in a .NET C# managed portable library that can be used by Native, Windows Store, and Windows Phone apps."
    If the Office 365 APIs will only be available when fully released as C# libraries that is a huge problem, especially if you want Windows Store App Developers to write apps that utilize data from it, even OData. There is a very large section of that dev community
    that write in JavaScript and you will essentially be ignoring and/or cutting off that whole segment of that community if you do. One of the great things about the Windows 8 App dev platform is that a developer can use (almost) any language that he/she is comfortable
    with, that HTML/Javascript and C#/XAML live, breath and thrive together. Unfortunately, it seems that the SharePoint product teams only are able to write in C#.
    It has been quite a struggle to write apps that utilize the SharePoint 2013 product line (on-prem, online, Project Online, etc) as a HTML/Javsacript Windows Store App developer, especially around authentication. No samples exist. The C# samples that do exist
    utilize coding methods that are very specific to how one would developer on the SharePoint platform before the new "app" dev model came about, which aren't necessarily the correct or appropriate ways that a Windows 8 developer would/should do things.
    It's like they didn't even bother to learn about the axioms and dev principals for Windows 8 Store Apps or worse didn't talk to their colleagues on the Windows Dev team.
    I write in both HTML/JavaScript and C#/XAML, which is not a common practice. However, when I am writing Windows 8 Store apps, HTML/JavaScript is the language that I prefer. It is just easier to get some of the more advance design things done in that language
    combination then in C#/XAML I have found. I have been holding off releasing some of my apps because I want to support O365/SharePoint Online/Project Online with them. If these new libraries are only going to be C#, then my apps just won't support O365. I would
    hope though that going forward that more support would be given to this large section of your customer community.
    Regards,
    Christine Flora

    Not sure if you've done a lot of work trying to get OData out of Office 365 / SharePoint Online or Project Online or done any Windows 8 development, but you must authenticate before you can even get TO the OData endpoints. So yes, the REST Endpoints are
    accessible by using an httpClient call from within Javascript, if in fact you can authenticate and authorize first.
    Currently this is a big pain in the backside, even if using C#, but from JavaScript it is almost impossible. Even now some of the current/popular methods for doing so can open big security holes on a Win8 machine (ie: running a claims service on your Win8
    machine locally just to authenticate to name just one).  I was hoping / am hoping that the new APIs will help with that, but I am not at all encouraged by what I am seeing and hearing so far especially since it looks like from the quote I provided above
    that they will only be available if you are using C#. As I pointed out, a large part of the Win8 App Dev community using JavaScript.
    I want to put it out there that I truly hope that the SharePoint product teams take this into consideration as they work on these new APIs and other ways to extend the SharePoint App family.
    Christine

  • Access to office 365 api

    Hi team, 
    i have been building up native applications and has access to Microsoft tenant in azure and there i have already the mobile application. Also i can add the webapi's to my application once when i went to configure tab and hit add on the bottom.
    So from here i can add office 365 exchange online api and set the delegated permissions to required field.
    Also i went through couple of articles and videos which shows how to get access to office 365 api.
    http://www.microsoftvirtualacademy.com/training-courses/deep-dive-integrate-office-365-apis-in-your-mobile-device-apps?m=11496
    As mentioned in video we add the connected service and it sign in to microsoft account and register the app.
    Also add some client id to App.xaml . And when we went to tenant application page we can see the new registered app with a client id.
    Please let me know if i already has the application in azure and i have added the office 365 exchange online api , then shall i need to do above steps or i can directly hit the api service Uri's.
    thanks,
    NItesh

    Hi,
    need to add the office 365 exchange online web api in Azure and set the required permissions.
    then following this video code we can connect with office apis
    http://www.microsoftvirtualacademy.com/training-courses/deep-dive-integrate-office-365-apis-in-your-mobile-device-apps?m=11496
    also following url can be referred if we need directly to communicate with office 365 api using Oauth authentication method.
    https://msdn.microsoft.com/en-us/office/office365/api/api-catalog
    Thanks,
    Nitesh

  • Having trouble removing a student email account from the Windows Mail App because the school has started using office 365 for thier email which i dont have access to

    I was wondering if anybody has any ideas on how to remove a gmail account that was set up by a community college for use on their mail servers and then find out that after awhile they have locked you out because they have started using office 365 for their
    emails and you are left with a student email account that you have no idea how to delete because you have missied out on deleting it before they changed to a different email provider?
    Anybody with ideas please help because I don't know what to do

    Hi,
    Regarding to Windows Mail App, do you mean the Modern UI App in Windows 8.1? Do you mean that you want to remove the email account from Mial App? Generally, we can simply remove the account by the "Account" option in Mail App (Open Mail App, move
    the mouse the right chram bar, click Account, then click the mail account\Remove account), but if the email acocunt is tied with the Microsoft Account which is used on the pc, in that case, it is unavailable to remove the email account, you need to contact
    your college to disconnect the Microsoft Account.
    If I'm misunderstanding something, please free correct me.
    Regards
    Yolanda Zhu
    TechNet Community Support

  • Query about using Office 365 as a file server

    Hey,
    At my workplace we are looking to change our method of storing files, as it stands we have an old machine which we connect to via the LAN.
    As we have expanded, other people need access to this from afar and we have looked at Office 365 Education, my understanding is that everyone gets 25gb on their own local area. How would we go about getting 100-200 GB of space on a standalone area.
    E.G a virtual server which everyone can access, as an admin can I restrict who views which directories? 
    My understanding is that I would need to make a user account called "Company Server" and share the folders via SkyDrive and only upgrade that account?
    Thanks again

    The storage for OneDrive for Business (SkyDrive Pro) is now 1TB for each user. OneDrive for Business is a good place for storing users' working files, the kinds of files you'd typically find in user home directories.
    You can use Office 365 like a file server through the use of mapped network drives. Here's how to set one up support.microsoft.com/en-us/kb/2616712. You can also script the network drive setup process with Powershell. Check
    http://www.lieben.nu/numb3rs/?page_id=129 and
    http://office365drivemap.codeplex.com/
    Myles Jeffery | Thinkscape Limited
    Try mapping OneDrive for Business and team site libraries to network drives with Zee Drive, its easy!
    Try our file share migration tool for OneDrive for Business and SharePoint Online Office 365

  • Office 365 API: work hours and private appointments

    Hi,
    We have application that supports Exchange on-premis and we wont to add Office 365 support. For that we need to be able to obtain same information that we use currently with our on-premis solution.
    Does Office 365 API support retrieving information about user work hours and events that are marked as private? I haven't found this in documentation https://msdn.microsoft.com/en-us/office/office365/api/api-catalog
    Best regards
    Krzysztof Branicki

    Hi Krzysztof,
    Thanks for posting here!
    This forum is for Azure Active Directory and your query is about Office365.
    Microsoft has dedicated forums for Office 365 commercial support. To ensure you
    connect with the right experts
    please post your question to
    http://community.office365.com/en-us/f/default.aspx. Also, if you use your Organizational email address for your first-time log-on you will have a more personalized experience.   
    I am archiving this thread from my end as there is no action required from Azure AD Forum (MSDN Forum).
    Best Regards,
    Sadiqh

  • Office 365 API, error: The token has invalid value 'roles' for the claim type ''

    Hi guys,
    I am trying to develop a Daemon / Server application using the new Office 365 APIs. I have added a new application to Azure Active Directory. I am using cURL + the app ID and secret to get a JWT token, this is the exact request:
    curl -X POST https://login.windows.net/TENANT_KEY/oauth2/token \
    -F redirect_uri=http://spreadyDaemon \
    -F grant_type=client_credentials \
    -F resource=https://outlook.office365.com/ \
    -F client_id=XXXX \
    -F client_secret=XXXX=
     I get back a JWT however it has no scopes for access set here is the decoded JWT claims:
    "ver": "1.0",
    "aud": "https://outlook.office365.com/",
    "iss": "https://sts.windows.net/TENANT_KEY/",
    "oid": "17fa33ae-a0e9-4292-96ea-24ce8f11df21",
    "idp": "https://sts.windows.net/TENANT_KEY/",
    "appidacr": "1",
    "exp": 1415986833,
    "appid": "XXXX",
    "tid": "e625eb3f-ef77-4c02-8010-c591d78b6c5f",
    "iat": 1415982933,
    "nbf": 1415982933,
    "sub": "17fa33ae-a0e9-4292-96ea-24ce8f11df21"
    Therefore when I do a request to the exchange API endpoint I get the following response:
    HTTP/1.1 401 Unauthorized
    Cache-Control: private
    Server: Microsoft-IIS/8.0
    request-id: d08d01a8-7213-4a13-a598-08362b4dfa70
    Set-Cookie: ClientId=WDALDNO0CAIOOZDZWTA; expires=Sat, 14-Nov-2015 16:40:59 GMT; path=/; HttpOnly
    X-CalculatedBETarget: am3pr01mb0662.eurprd01.prod.exchangelabs.com
    x-ms-diagnostics: 2000001;reason="The token has invalid value 'roles' for the claim type ''.";error_category="invalid_token"
    X-DiagInfo: AM3PR01MB0662
    X-BEServer: AM3PR01MB0662
    X-AspNet-Version: 4.0.30319
    Set-Cookie: exchangecookie=6bf68da033684824af21af3b0cdea6e3; expires=Sat, 14-Nov-2015 16:40:59 GMT; path=/; HttpOnly
    Set-Cookie: [email protected]=[email protected]4Wbno2ajNGQkZKWnI2QjJCZi9GckJKBzc/Oy9LOzdLOy6vOycXLz8XKxoGaio2PjZvPztGPjZCb0ZqHnJeekZiak56djNGckJI=; expires=Sun, 14-Dec-2014 16:40:59 GMT; path=/EWS; secure; HttpOnly
    Set-Cookie: [email protected]=[email protected]4Wbno2ajNGQkZKWnI2QjJCZi9GckJKBzc/Oy9LOzdLOy6vOycXLz8XKxg==; expires=Sun, 14-Dec-2014 16:40:59 GMT; path=/EWS; secure; HttpOnly
    X-Powered-By: ASP.NET
    X-FEServer: DB4PR02CA0026
    WWW-Authenticate: Bearer client_id="00000002-0000-0ff1-ce00-000000000000", trusted_issuers="00000001-0000-0000-c000-000000000000@*", authorization_uri="https://login.windows.net/common/oauth2/authorize", error="invalid_token",Basic Realm="",Basic Realm=""
    Date: Fri, 14 Nov 2014 16:40:59 GMT
    Content-Length: 0
    I have asked a stack overflow question here: http://stackoverflow.com/questions/26950838/office-365-api-error-the-token-has-invalid-value-roles-for-the-claim-type
    Any help on the matter will be hugely appreciated, thanks!

    Hi Manu,
    To wrap this thread up; I have had an answer on stack overflow.
    It appears that currently the grant type client_credentials is not supported, according to a comment on this blog post by Matthias' http://blogs.msdn.com/b/exchangedev/archive/2014/03/25/using-oauth2-to-access-calendar-contact-and-mail-api-in-exchange-online-in-office-365.aspx 
    "There is no way in the code flow to avoid username/password. We're working on a client credential flow for later this fall that will give you the functionality required to run background services. For this you will not need a username/password,
    but the application will directly assert its identity and authenticate as itself."
    Unfortunately I require client_credentials for a daemon process, Q4 is the scheduled release for support for this grant time.
    Thanks for the help,
    Nick

  • Cannot click in search mail and people field using Office 365

    As of this week, four of the users in our school have reported that they cannot click within the search mail field using Office 365. Happens on Macs running 10.8 and 10.9 when using Firefox version 28. When they try using Google Chrome they can use the email search function.
    Is anyone else having this issue? Any ideas? I updated to the latest versions of Flash and Java same result.
    Thank you!

    Hi CT_Dave, I do know that search api can have alot of dom elements on them and that scripts on a page can be prevented from running. However, for Office 365 specifically I do not know what kind of search they have.
    You can monitor the search page by looking in the web console to see if there are any specific errors that may be causing this issue.
    In the about:config, please also make sure javascript is enabled.
    # In the address bar, type "about:config" (with no quotes), and press Enter.
    # Click "I'll be careful, I promise"
    # In the search bar, search for "javascript.enabled" (with no quotes).
    # Right click the result named "javascript.enabled" and click "Toggle". JavaScript is now disabled.
    To Re-enable JavaScript, repeat these steps.

  • Replication of contacts in iPhone 4 using office 365 online

    We are using Office 365 Online mail service in our organization. One of our Director is using Mac, iPhone 4 & iPad to access his mails. He is having some problem in his Contacts. Some of contatcs replicated in the list again and again. We have tried to rectify the problem as instructions received from our service provider but same problem occur again.
    We have applied following operations on iPhone :
    * Removed duplicate contacts from MS Exchange Online and removed contacts on iPhone 4 and re-sync.
    * Removed Exchange id from iPhone 4 and re-create id on iPhone 4.
    We have never sync iPhone 4 contacts through iTunes or iCloud.
    Our Director using 4 MS Exchange online ID on his all apple devices. His Contacts and Calendar associated with only on id.

    You should setup domain for Office 365 - Add your users and domain to Office 365
    [custom.development]

  • Missing e-mails on computers when using office 365 outlook

    I am using office 365, things were working well but I do faced with a problem.
    As my emails were from Exchange and I am using IMAP in my email settings on my computer and mobile devices, when I create folders and stored my emails in these folders on my computer, some of my emails disappeared, but when I check login and check the
    web-version of e-mails, they are inside there.
    Can anyone advise how to stop this problem or disappearing emails and how to synchronise these emails back to my computer ?
    Thank you

    Hi,
    So you are using IMAP to access your mail on Exchange on your computer and mobile. Some emails will disappear after move them to a folders on the computer.
    Based on my research, this issue can happen for several reasons, for example a client filter, corruptions in data file or Outlook profile, etc.
    I would suggest we try following steps to troubleshoot the issue:
    Check if you have any filter view settings applied on these folders which might filter out these emails. Click
    VIEW>View Settings on the ribbon, then click Filter...
    Check with a new Outlook data file, and see if issue persists. You can simply delete the current .ost file, and launch Outlook again to let it generate a new one. To check the location of your Outlook data file, please
    go to FILE>Account Settings>Account Settings>Data Files
    tab.
    If issue persists, you might want to check with a new Outlook profile:
    https://support.office.com/en-us/article/Create-an-Outlook-profile-f544c1ba-3352-4b3b-be0b-8d42a540459d
    Hope this helps.
    Regards,
    Ethan Hua
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

Maybe you are looking for

  • Itunes 11 keeps changing my screen resolution

    I too am an itunes 11 sufferer!    Everytime I run it, it alters my screen resolution - I'd happily upgrade to the older, better, bug-free version that I was running before,but am afraid i might lose my library of music.  In trying to find a solution

  • FCC..how to remove first row

    Hello experts, I have configured a end to end sccenario fo csv files, Im using fcc for the sender file adapter The first row has all the field names such as name,number and the rest of the rows have the values. when I run the scenario the xml being f

  • IMAP-Mail sender adapter handling with read messages in mailbox

    Hi, (PI 7.0) we have a "funny" situation: We are using imap-mail-sender adapter polling a mailbox. Sometimes there are read messages in mailbox so the adapter cannot read these messages. When we sort all read messages and we mark e.g. the second mess

  • How can i connect a hardware VTEP gateway to a NSX controller?

    I have a hardware VTEP gateway which supports OVSDB configuration but there is no SSL support over OVSDB. Can  anyone suggest is there a way to configure the hardware VTEP to the controller without SSL. What about the idea of using a intermediate nod

  • Exchange Rate Derivation Error

    Hello Expert, While posting a document in currency ZAR we are getting an error that "ER between ZAR/USD is not maintained" and hence the document can not be saved. The company code currency is ZAR and OB22 we have defined ER Type M for local currency