Frequently used REST APIs – Part 2

fig : Power Automate - using "Send an HTTP request to SharePoint' action to add user to given SharePoint Group
fig : Power Automate - using "Send an HTTP request to SharePoint' action to add user to given SharePoint Group

Hi All,

Greetings for the day!!!

While doing SharePoint / Power Platform / Teams development we most of the time need to use REST APIs and then need to google. This is the reason – birth of these series of articles. Thought to keep all REST APIs together so that whenever need can find quickly.

This is part 2 in series. First part is here – Frequently used REST APIs – Part 1

Get the SharePoint group ID or specific group details from group name

  • Method : GET
_api/web/siteGroups/getByName('<GROUP NAME>')

OR

 _api/web/sitegroups?$filter=LoginName eq '<GROUP DISPLAY NAME>'&$select=Id&top=1

fig : Power Automate - using "Send an HTTP request to SharePoint' action to get the GroupID from Group display name / login name
fig : Power Automate – using “Send an HTTP request to SharePoint’ action to get the GroupID from Group display name / login name

https://knowledgejunction1.sharepoint.com/_api/web/siteGroups/getByName('Communication%20site%20Members')

fig : Rest API Demo - Get the SharePoint group ID or specific group details from group name
fig : Rest API Demo – Get the SharePoint group ID or specific group details from group name

Add user to SharePoint group

  • Method : POST
_api/web/sitegroups(⁠GroupID⁠)/users

and in body of an action - "Send an HTTP request to SharePoint" we will specify the user claim as 

{
"__metadata":{"type":'SP.User'},
 'LoginName':'i:0#.f|membership|prasham@knowledgejunction1.onmicrosoft.com'
}

fig : Power Automate - using "Send an HTTP request to SharePoint' action to add user to given SharePoint Group
fig : Power Automate – using “Send an HTTP request to SharePoint’ action to add user to given SharePoint Group

Get the root folder of your Shared Documents library

/_api/web/GetFolderByServerRelativeUrl('<document library folder relative URL>') 


https://knowledgejunction1.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents') 

fig : SharePoint Online - REST API - Read the document library / Get root folder of Document Library
fig : SharePoint Online – REST API – Read the document library / Get root folder of Document Library

Get all files in a folder – Get all files from Document library

/_api/web/GetFolderByServerRelativeUrl('<document library folder relative URL>')/Files


https://knowledgejunction1.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files

fig : SharePoint Online - REST API - Fetch all files from folder / Get all files from document library
fig : SharePoint Online – REST API – Fetch all files from folder / Get all files from document library

Get specific file from the document library – from name of file

https://knowledgejunction1.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('<document library folder relative URL>')/Files('<file name>')


https://knowledgejunction1.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files('config.cfg')

fig : SharePoint Online - REST API - Fetch specific file from file name
fig : SharePoint Online – REST API – Fetch specific file from file name

Get specific file from the document library – from URL of file

/_api/web/GetFileByServerRelativeUrl('<file relative path>')


https://knowledgejunction1.sharepoint.com/_api/web/GetFileByServerRelativeUrl('/Shared%20Documents/config.cfg')

fig : SharePoint Online - REST API - Fetch specific file from file URL
fig : SharePoint Online – REST API – Fetch specific file from file URL

    Fetch all files attached with List Item

    https://{site_url}/_api/web/lists/getbytitle('{list_title}')/items({item_id})/AttachmentFiles/
    
    
    Example 
    
    https://knowledgejunction1.sharepoint.com/_api/web/lists/getbytitle('Demo%20Email%20To%20SP%20Group')/items(1)/AttachmentFiles/ 

    fig : SharePoint Online - REST API - Fetch all attachments of given List Item
    fig : SharePoint Online – REST API – Fetch all attachments of given List Item

    Fetch specific attachment file for given List Item

    https://{site_url}/_api/web/lists/getbytitle('{list_title}')/items({item_id})/AttachmentFiles({attachment_name})
    
    
    Example
    
    https://knowledgejunction1.sharepoint.com/_api/web/lists/getbytitle('Demo%20Email%20To%20SP%20Group')/items(1)/AttachmentFiles('thumbnail.jpg')

    fig : SharePoint Online - REST API - Fetching attachment by name of given List Item
    fig : SharePoint Online – REST API – Fetching attachment by name of given List Item

    Thanks for reading !!! If its worth at least reading once, kindly please like and share !! SHARING IS CARING 🙂

    Enjoy the beautiful life !!! Have a FUN !!! HAVE A SAFE LIFE !!! TAKE CARE 🙂

    Prasham Sabadra

    LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

    You may also like...

    1 Response

    1. January 25, 2023

      […] Second part – Frequently used REST APIs – Part 2 […]

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    %d bloggers like this: