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

Blogs
30 Sep, 2024

SMS Integration with Twilio Number in D365 Customer Service- Part 1

Introduction Integrating SMS functionality into Dynamics 365 can significantly enhance customer communication by providing a direct and efficient channel for…

READ MORE
Blogs
24 Sep, 2024

White Box Testing - Its Techniques and Types

In this blog, we’ll deal with one of the most popular methods of testing a system or system component thoroughly…

READ MORE
Case Study
06 Sep, 2024

Implementation of Business Central for a Trading Organization

Customer Overview A prominent trading organization sought to enhance its operational efficiency and streamline its business processes by implementing Dynamics…

READ MORE