Microsoft Outlook 365 Integration with Salesforce Using REST API with Demo
Here is the demo of the same built on Salesforce using Salesforce Sites. (https://msofficeintegration-developer-edition.ap5.force.com/)
In this post, we will learn how to connect Salesforce with Outlook 365 using REST API.
For this, the first step is to create an Application in the “Microsoft App Registration Portal” (https://apps.dev.microsoft.com/). Log in using your office 365 account credentials.
Click on Add an App button to start creating the application. Enter the Application Name and click create. Now do as mentioned in the snapshot below:
Save the changes.
Once done create a URL in the format below:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=id_token+token&client_id=c68aa37b-07a9-42f9-bc81-78cbcf49bda5&redirect_uri=https://msofficeintegration-developer-edition.ap5.force.com&scope=openid+profile+User.Read+Mail.Read+Mail.ReadWrite+Calendars.Read+Calendars.ReadWrite+Contacts.ReadWrite&state=f175f48d-d277-9893-9c8d-dcc2a95ffe16&nonce=c68aa37b-07a9-42f9-bc81-78cbcf49bda5&response_mode=fragment
Replace below values:
client_id value with your application Client ID.
redirect_uri with the page where you would like the user to redirect after authorization.
nonce should be same as your client id.
once the user authenticates on the above link he will be redirected to the URL you have configured in the app along with the #access_token
This access token now can be used to send REST call to Microsoft to fetch details.
Microsoft graph API's details and examples can be explorer using Graph Explorer. (https://developer.microsoft.com/en-us/graph/graph-explorer).
Sample code for fetching latest emails
HttpRequest request = new HttpRequest();
request.setEndpoint('https://graph.microsoft.com/v1.0/me/MailFolders/inbox/messages');
request.setMethod('GET');
AuthoriztionValue= 'bearer ' + Access_token; returned after Authorization
request.setHeader('Authorization', AuthoriztionValue);
request.setHeader('Accept', 'text/html, image/gif, image/jpeg, application/json');
request.setHeader('Prefer', 'outlook.allow-unsafe-html');
String responsebody = (new Http()).send(request).getBody();
system.debug('*****response*******'+responsebody);
RespBody= responseBody;
Here is the demo of the same built on Salesforce using Salesforce Sites. (https://msofficeintegration-developer-edition.ap5.force.com/)
can you Provide the sample visualforce and Apex code
ReplyDeleteHi Saurabh,
ReplyDeleteCan you please share the code of Apex class and Vf if you have.My requirement is to sync outlook and salesforce. But it seems we can not use standard saleforce sync as it syncs only one way.Also,there are number of paid app but my client needs custom solution.Do you thing above solution works for my requirement.Can you please help me on this?
Hello Saurabh , This article looks so helpful. I needed fully custom solution for outlook integration to salesforce , Just wanted to make sure that does this work the same way
ReplyDelete2nd question is that can we change visual force page url with lightning page url.
Looking for reply, Thank you!!