Describe the different steps for connecting Magic xpi with SharepointOnline using REST Sharepoint API (*)
(*) Sharepoint can be accessed also via REST Microsoft Graph API (not described in this post)
Goal : Download files from Sharepoint Online Folder
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_12-1024x326.png)
1/ Check that you can call REST Sharepoint Online API using Postman with your credentials
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_1-1.png)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_2-1024x567.png)
(*) client_id, client_secret, tenantid and resource can be generated using these steps below
1.1 Navigate to : https://<YourSharePointCollectionURL>/_layouts/15/appregnew.aspx to register a new Sharepoint app
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_3.png)
1.2 after generating client id and client secret, navigate to :
https://<YourSharePointCollectionURL>/_layouts/15/appinv.aspx to grant permission to your app
fill the information and copy/paste the xml below in the field Apps permission request XML
<AppPermissionRequests AllowAppOnlyPolicy=”true”> <AppPermissionRequest Scope=”http://sharepoint/content/sitecollection/web” Right=”FullControl” /> </AppPermissionRequests>
1.3 Navigate to : https://<YourSharePointCollectionURL>/_layouts/15/appprincipals.aspx to get the tenantid and clientid with @
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_4.png)
2/ Create a New Magic xpi Flow with a Flow Data Step first and update a variable with the body credentials
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_5.png)
3/ Create a REST Client Magic xpi resource to navigate to https://accounts.accesscontrol.windows.net to get the Bearer token (Project=>Settings=>Resources)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_6-1024x289.png)
4/ Use REST Client Connector to call the previous URL
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_7-1.png)
5/ Parse the json response to get the token using a Flow Data Component
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_8.png)
6/ Create a REST Client Magic xpi resource to call sharepoint methods (Project=>Settings=>Resources)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_9.png)
7/ Drag and Drop a REST Client Connector linked to the previous resource and configure the connector to set the path {List} with Get operation.
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_10-1.png)
8/ Update list parameter with the expression : ‘GetFolderByServerRelativeUrl(”<FolderPath>”)/files‘
example : GetFolderByServerRelativeUrl(”/sites/MSE-France/SaadLibrary2/test2”)/files
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_11.png)
9/ Drag and Drop a Datamapper component to parse the result and make a loop to call another flow that will responsible to download the file
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_13-1024x285.png)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_14.png)
Set F.FileName and F.RelativeURL variables with Name and ServerRelativeURL.
10/ Create another path in the resource repository {monpath}
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_15-1-1024x304.png)
11/ Drag & Drop a REST Client connector and right click to configure the connector
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_16.png)
Set monpath parameter with the expression : ‘GetFolderByServerRelativeUrl(”’&Trim (F.RelativeURL)&”’)/Files(”’&Trim (F.FileName)&”’)/$Value‘
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_17.png)
12/ Drag & Drop a FileManagement component to save the file on the disk
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_18-1024x557.png)
13/ If the previous step “Get File” is successfull then delete the file on sharepoint folder
Create another path in the resource repository {delete}
Don’t forget to set in the header : X-HTTP-Method to DELETE
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_19-1024x409.png)
14/ Drag & Drop a REST Client connector to call the delete method at the end of the flow
Choose a Post operation
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_20.png)
Update the parameter delete with the expression : ‘GetFolderByServerRelativeUrl(”’&Trim (F.RelativeURL)&”’)/Files(”’&Trim (F.FileName)&”’)’
![](https://france.magicsoftware.com/blog/wp-content/uploads/2023/11/SharepointOnline_21.png)
15/ Document reference : https://www.c-sharpcorner.com/article/how-to-test-sharepoint-online-rest-apis-using-postman-tool/