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

Ad hoc support Thumbnail image
Blogs
12 Mar, 2025

What is Ad hoc Support and Why Was It Created?

What is Ad hoc Support and Why Was It Created? Businesses today are constantly navigating obstacles that need swift and…

READ MORE
Data Migration thumbnail
Blogs
11 Mar, 2025

Data Migration: On-Premises to Cloud CRM Systems - A Step-by-Step Guide

Data Migration: On-Premises to Cloud CRM Systems - A Step-by-Step Guide Many businesses are moving their CRM systems from on-premises…

READ MORE
D365 Customer Service - Thumbnail
Blogs
03 Mar, 2025

What Is Dynamics 365 Customer Service?

What Is Dynamics 365 Customer Service? Dynamics 365 Customer Service is a powerful solution by Microsoft designed to enhance customer…

READ MORE