10 SharePoint Send HTTP Request API Examples in Power Automate

10 SharePoint Send HTTP Request API Examples in Power Automate

SharePoint and Power Automate are powerful tools in Microsoft's ecosystem that, when combined, can automate a myriad of business processes. One of the most effective ways to harness their full potential is through the "Send HTTP Request to SharePoint" action in Power Automate. This action allows you to interact with the SharePoint REST API, providing granular control over your SharePoint data and operations. In this article, we'll explore ten practical examples of using the "Send HTTP Request to SharePoint" action in Power Automate.


1. Creating a SharePoint List

Creating a new SharePoint list programmatically can save time, especially when setting up multiple sites or lists with similar structures. Using the HTTP Request action, you can define the list structure and fields in a JSON payload.

Example:

{

    "uri": "_api/web/lists",

    "method": "POST",

    "body": {

        "__metadata": { "type": "SP.List" },

        "AllowContentTypes": true,

        "BaseTemplate": 100,

        "ContentTypesEnabled": true,

        "Description": "New List Description",

        "Title": "New List Title"

    }

}        

2. Updating List Items

Automating the update of list items can streamline workflows significantly. By specifying the list and item ID, you can update specific fields of a list item. The Update list tem HTTP Request is particularly interesting for SharePoint with threshold problems regarding the number of columns lookup and people picker.

Example:

{

    "uri": "_api/web/lists/GetByTitle('YourListTitle')/items(ItemId)",

    "method": "MERGE",

    "headers": {

        "IF-MATCH": "*",

        "X-HTTP-Method": "MERGE"

    },

    "body": {

        "__metadata": { "type": "SP.Data.YourListNameListItem" },

        "Title": "Updated Title",

        "Description": "Updated Description"

    }

}        

3. Deleting List Items

Automating the deletion of list items can help maintain data hygiene and enforce retention policies.

Example:

{

    "uri": "_api/web/lists/GetByTitle('YourListTitle')/items(ItemId)",

    "method": "DELETE",

    "headers": {

        "IF-MATCH": "*"

    }

}        

4. Retrieving List Items

Fetching list items based on specific criteria can help in reporting and data aggregation tasks. The GET method can be used to filter and retrieve items.

Example:

{

    "uri": "_api/web/lists/GetByTitle('YourListTitle')/items?$filter=Title eq 'Specific Title'",

    "method": "GET"

}        

5. Creating Folders

Folders help in organizing content within SharePoint libraries. The HTTP Request action allows the creation of folders within a document library.

Example:

{

    "uri": "_api/web/folders",

    "method": "POST",

    "body": {

        "__metadata": { "type": "SP.Folder" },

        "ServerRelativeUrl": "/sites/YourSite/Shared Documents/NewFolder"

    }

}        

6. Uploading Files

Automate the upload of files to SharePoint libraries using the HTTP Request action. This can be useful for automated document processing workflows.

Example:

{

    "uri": "_api/web/GetFolderByServerRelativeUrl('/sites/YourSite/Shared Documents')/Files/add(url='filename.txt',overwrite=true)",

    "method": "POST",

    "body": "Base64 encoded file content"

}        

7. Checking Out and Checking In Files

Automate the check-out and check-in process to ensure document version control and avoid conflicts during edits.

Example: Checking Out

{

    "uri": "_api/web/GetFileByServerRelativeUrl('/sites/YourSite/Shared Documents/filename.txt')/checkout",

    "method": "POST"

}        

Example: Checking In

{

    "uri": "_api/web/GetFileByServerRelativeUrl('/sites/YourSite/Shared Documents/filename.txt')/checkin(comment='Check-in via API',checkintype=0)",

    "method": "POST"

}        

8. Managing Permissions

Modify permissions on SharePoint items to control access programmatically, ensuring that sensitive information is protected.

Example:

{

    "uri": "_api/web/lists/GetByTitle('YourListTitle')/items(ItemId)/roleassignments/addroleassignment(principalid=UserOrGroupId,roledefid=RoleDefinitionId)",

    "method": "POST"

}        

9. Adding Users to Groups

Automate the addition of users to SharePoint groups to streamline user management and onboarding processes.

Example:

{

    "uri": "_api/web/sitegroups/GetByName('YourGroupName')/users",

    "method": "POST",

    "body": {

        "__metadata": { "type": "SP.User" },

        "LoginName": "domain\\username"

    }

}        

10. Creating Site Collections

Automate the creation of new site collections, which can be beneficial for organizations with dynamic project or department-based sites.

Example:

{

    "uri": "_api/SPSiteManager/create",

    "method": "POST",

    "body": {

        "request": {

            "__metadata": { "type": "Microsoft.SharePoint.Portal.SPSiteCreationRequest" },

            "Title": "New Site Title",

            "Url": "https://yourtenant.sharepoint.com/sites/newsite",

            "Lcid": 1033,

            "ShareByEmailEnabled": false,

            "SiteDesignId": "SiteDesignId",

            "WebTemplate": "64",

            "Owner": "[email protected]"

        }

    }

}        

Summary

The "Send HTTP Request to SharePoint" action in Power Automate is a powerful tool for automating a wide range of SharePoint operations. From creating and managing lists to handling permissions and site collections, these examples demonstrate how you can leverage the SharePoint REST API to streamline your business processes. By integrating these actions into your workflows, you can enhance productivity and ensure efficient management of your SharePoint environment.

Shaswar Shali

????R&D Lead Mircrosoft Projects | Master of Science from Salford | AI Enthusiast | Agile Project Management | Microsoft 365 & Data Analyst | Driving Innovation through Research and Technology Integration

3 个月

Is thos method is true: ```json { '__metadata': { 'type': 'SP.Data.ListNameListItem' }, 'Title': 'New Item' } ```

回复
Huib Versnel

magazijnmedewerker, verbinder, mantelzorger, out of the box ; ADHD met ADD

3 个月

Comment for better reach and visibility in my network Marcel Broschk

要查看或添加评论,请登录

社区洞察

其他会员也浏览了