knowledgecenter-breadcrum

Knowledge Center

15 Apr, 2024

Create SharePoint list items using the Microsoft Graph API and Azure Functions locally

Posted on 15 Apr, 2024 by Ankit Gore, Posted in Azure Function

Blogs

In this blog, we will explore how to create SharePoint list items using the Microsoft Graph API and Azure Functions locally. 

Many developers prefer a local development experience. When you use Functions, using your favorite code editor and development tools to create and test functions on your local computer becomes easier. Your local functions can connect to live Azure services, and you can debug them on your local computer using the full Functions runtime.

You can find more details about this over here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local

Prerequisites:

  1. Visual Studio 2022, with the Azure development workload installed.
  2. Register a new app on Azure if not already done.
    • Make a note of the Client ID, client secret of the app, and the tenant ID of the Azure portal.
  3. SharePoint list ID and site ID are also required.

Steps to perform:

  1. Create a new Azure function(HTTP trigger) project in Visual Studio 2022.

      

  1. Folder structure
    • Below, we created a 'Common' folder and added the 'common.cs' file inside it for common functions.

     

  1. Let's write the code.
    declare the global variables.


     
  2. Set the values of the global variable and call the function to get the Graph client.
  3. Add the 'get graph client' function in the common file
  4. Create the static dummy JSON data to insert in SharePoint list.

  1. Now deserialize the JSON data and create the class file for the item.

        

  1. Create request body for each item.

      

  1. Now, create an item using the request body inside the foreach loop.
    var result = graphClient.Sites["Test.sharepoint.com%2Cf664ea30-3595-405a-9883-ec39f450601e%2Cd3eff99d-a1e5-4757-b24a-a78e373d2a74"].Lists["f93896fc-0672-4844-97a7-b334d1ed3771"].Items.PostAsync(requestBody);
  2. Return the response at the end.

    

  1. Output
    
    SP list:
    
    

Hope you find this helpful!!

Comment

This is a Required Field

Loading

Recent Updates

Thumbnail Image of ROI
Blogs
17 Jun, 2025

Maximizing ROI with Power Apps: The Role of Expert Consulting Services

Maximizing ROI with Power Apps: The Role of Expert Consulting Services Explore how skilled professionals can get you the best…

READ MORE
Digital transformation thumbnail
Blogs
12 Jun, 2025

How Microsoft 365 Consulting Can Drive Digital Transformation for Your Organization

How Microsoft 365 Consulting Can Drive Digital Transformation for Your Organization Digital transformation boasts way more than just shifting from…

READ MORE
Blogs
12 May, 2025

How to create an Autonomous Agent in Copilot Studio

What Are Autonomous Agents in Copilot Studio? Autonomous agents are AI-driven entities that operate independently within Copilot Studio. They go…

READ MORE