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
16 Jul, 2024

How to use Solutions with Power Pages

What is Solution in power Pages? A solution is a container for components such as Website Configuration and Dataverse Components.…

READ MORE
Blogs
15 Jul, 2024

Create a Dataverse table with a SharePoint List

In today’s business world, Organization uses SharePoint lists for document management, and data storage. Let's assume a scenario where an organization…

READ MORE
Case Study BW - Nebulaa IT Solutions
Case Study
03 Jul, 2024

Revolutionizing Build Warranty's Operations with a Scalable and Automated Dynamics 365 Solution

Customer Overview Build Warranty (BW), a leading UK-based provider of warranty solutions for the construction industry, sought a strategic partner…

READ MORE