Describe the different steps for connecting Magic xpi with Office365 using REST Microsoft Graph API
1/ Define in Azure Portal An app registration and add permission for Office365 via Microsoft Graph
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG1-1024x516.png)
Retrieve the ClientId, ClientSecret, TenantId in other to define this settings in the Magic xpi Resource Repository
2/ Open the Resource repository in Magic xpi Studio
Define all the settings like below
Set the scope with : offline_access IMAP.AccessAsUser.All
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG2-1024x350.png)
3/ Click on the Paths Button and define 4 endpoints
/users/{id}/mailfolders/inbox/messages
/users/{id}/mailfolders/inbox/messages/{messageid}/attachments/{attachid}/$value
/users/{id}/mailfolders/inbox/messages/{messageid}/attachments
/{attachment_path}
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG3-1024x608.png)
4/ Drag and Drop a REST Client connector and use /users/{id}/mailfolders/inbox/messages endpoint
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG4.png)
Set the Id with the User uuid
(*) You can make a GET on https://graph.microsoft.com/v1.0/users/{Mailbox] to retrieve the UserUUID
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG5-1024x288.png)
5/ Drag and Drop Datamapper connector to make a loop in other to download Mail attachments by calling a Subflow and passing the Id
(*) In the example, we process only Mails that has attachment
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG6-1024x312.png)
6/ In the called subflow, Make a GET on this URL : /users/{id}/mailfolders/inbox/messages/{messageid}/attachments
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG7-1024x353.png)
Click OK and pass the MessageID and User UUID
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG8-1024x349.png)
7/ Parse the JSON response and call another subflow to download Mail Attachment by passing the Name and AttachmentID
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG9-1024x356.png)
8/ In the second subflow, make a get on this URL : /{attachment_path}
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG10-1024x374.png)
set attachment_path : ‘/users/{User UUID}/mailfolders/inbox/messages/{MessageId}/attachments/{AttachId}/$value‘
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG11-1024x335.png)
Use the FileManagment to save the file content locally
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/06/OFFICE365_MG12-1024x407.png)