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
1/ Check that you can call REST Sharepoint Online API using Postman with your credentials
(*) 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
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 @
2/ Create a New Magic xpi Flow with a Flow Data Step first and update a variable with the body credentials
3/ Create a REST Client Magic xpi resource to navigate to https://accounts.accesscontrol.windows.net to get the Bearer token (Project=>Settings=>Resources)
4/ Use REST Client Connector to call the previous URL
5/ Parse the json response to get the token using a Flow Data Component
6/ Create a REST Client Magic xpi resource to call sharepoint methods (Project=>Settings=>Resources)
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.
8/ Update list parameter with the expression : ‘GetFolderByServerRelativeUrl(”<FolderPath>”)/files‘
example : GetFolderByServerRelativeUrl(”/sites/MSE-France/SaadLibrary2/test2”)/files
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
Set F.FileName and F.RelativeURL variables with Name and ServerRelativeURL.
10/ Create another path in the resource repository {monpath}
11/ Drag & Drop a REST Client connector and right click to configure the connector
Set monpath parameter with the expression : ‘GetFolderByServerRelativeUrl(”’&Trim (F.RelativeURL)&”’)/Files(”’&Trim (F.FileName)&”’)/$Value‘
12/ Drag & Drop a FileManagement component to save the file on the disk
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
14/ Drag & Drop a REST Client connector to call the delete method at the end of the flow
Choose a Post operation
Update the parameter delete with the expression : ‘GetFolderByServerRelativeUrl(”’&Trim (F.RelativeURL)&”’)/Files(”’&Trim (F.FileName)&”’)’
15/ Document reference : https://www.c-sharpcorner.com/article/how-to-test-sharepoint-online-rest-apis-using-postman-tool/