DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How Spring Boot Starters Integrate With Your Project
  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 7)
  • Scholcast: Generating Academic Paper Summaries With AI-Driven Audio
  • API and Security: From IT to Cyber

Trending

  • Medallion Architecture: Efficient Batch and Stream Processing Data Pipelines With Azure Databricks and Delta Lake
  • Understanding IEEE 802.11(Wi-Fi) Encryption and Authentication: Write Your Own Custom Packet Sniffer
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • Build Your First AI Model in Python: A Beginner's Guide (1 of 3)
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 6)

Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 6)

Explore an example to change a column value for a list item of a “user-defined” SharePoint list using a DriveItem, which also represents the PDF file.

By 
Constantin Kwiatkowski user avatar
Constantin Kwiatkowski
·
Sep. 16, 24 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
3.5K Views

Join the DZone community and get the full member experience.

Join For Free

This article discusses the following example: changing a column value for a list item of a “user-defined” SharePoint list, which represents a PDF file within a sub-folder of the SharePoint drive, using a DriveItem, which also represents the PDF file. SharePoint lists are central data structures that make it possible to store, organize, and manage information in tabular form. The test aims to demonstrate and explain how the MS-Graph API can be successfully used to change values in a list and correctly transfer this change to SharePoint. This ensures that the integrity of the file is maintained after the change and that no unexpected errors occur during API communication.

Microsoft Graph API

The Microsoft Graph API is a REST-based programming interface that provides access to a variety of services and data within the Microsoft 365 platform. It offers developers the ability to access a central interface to read, write, and manage data from services such as Azure Active Directory, Outlook, OneDrive, SharePoint, Microsoft Teams, and many more.

  • Access to Microsoft 365 data: Using the Graph API, developers can access user, group, calendar, email, file, task, and SharePoint data.
  • Identity and access management: It enables identities and access rights to be managed via Azure Active Directory, including user management, groups, and policies.
  • File management: The API can be used to create, modify, delete, or share files in OneDrive, SharePoint, and Teams.
  • Real-time communication: The API provides access to communication data from Outlook and Microsoft Teams such as emails, calendars, and chats.
  • It is a centralized API: Instead of using multiple APIs for different services (e.g., Outlook API, OneDrive API), the Microsoft Graph API provides a unified and consistent way to communicate.

SharePoint Lists and List Elements

A SharePoint list is a collection of data in SharePoint that is organized in the form of a table. It works similarly to a table in a database or an Excel spreadsheet and enables the storage, organization, and sharing of information within a SharePoint team or organization. Each list consists of columns, which can contain different types of data such as text, numbers, dates, people, or custom values, and rows, which are called list items. Each list has defined columns that describe the different types of information that belong to a list element (e.g., title, date, persons, metadata). Each line in a list represents a list element. This can be a data record or a file, e.g., a task, a contact, or a document in a document library. Lists can be easily customized by adding custom columns or changing the display order. There are different types of SharePoint lists:

  • Custom lists: Create and customize your lists with any columns and content.
  • Document library: A special list that contains documents (files), these are handled in the form of DriveItems and can be managed with metadata and versioning.
  • Announcements: A list for managing notifications or announcements
  • Task list: A list for tracking and managing tasks within a team
  • Contacts: A list for managing contact data

A DriveItem is a resource in the Microsoft Graph API that represents a file, folder, or other data entry within a drive (e.g., OneDrive, SharePoint document library). Each DriveItem can be an object that represents a file (e.g., PDF, Word document, image), a folder, or a link to an external resource. It serves as a central element for accessing and managing files and folders in Microsoft 365 via the Graph API.

Test Case

First, make sure that a valid access token for the Microsoft Graph API is available to obtain authorization to access SharePoint data. Use the following link to obtain the access token:

HTTP
 
https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/token


You need the TenantID, ClientID, and the ClientSecret to read this out. It is also important not to forget to define the appropriate rights on the Azure app. Next, the column to be read must be identified. The ListItem that represents the PDF file is retrieved from the SharePoint drive using the Microsoft Graph API. To do this, the SiteID, the DriveID, and the ListID must first be read.

SiteID

HTTP
 
https://graph.microsoft.com/v1.0/sites/${Hostname}:/sites/${Sitename}


${hostname} is the name of the SharePoint instance and ${sitename} is the name of the default site.

ListID

HTTP
 
https://graph.microsoft.com/v1.0/sites/${SiteID}/lists?filter=displayName eq ${DisplayName}&$select=id


${SiteID} is the ID of the page you want to read, and ${DisplayName} is the name of the subfolder. The select saves us, only the ID is returned.

DriveID

HTTP
 
https://graph.microsoft.com/v1.0/sites/${SiteID}/drives


As above, ${SiteID} is the ID of the site that you want to read out in SharePoint.
Once you have identified all three IDs — SiteID, DriveID, and ListID — the next step is to download the list of elements of a subfolder on SharePoint. This is done with the following call:

HTTP
 
https://graph.microsoft.com/v1.0/sites/${SiteID}/drives/${DriveID}/root:/${SubFolder}:/Children


Here, ${SiteID} and ${DriveID} are from the steps above and ${SubFolder} defines the relative path of the subfolder you want to read. The last call returns a list of so-called DriveItems.
In our case, a DriveItem represents the PDF that we want to read. With the last call, the so-called ${DriveItemID} is also read out for the items from the subfolder. Next, we need to read the so-called SharePoint IDs of a DriveItem so that we can determine the corresponding ListItemID of the DriveItemID. 

The call is as follows:

HTTP
 
https://graph.microsoft.com/v1.0/sites/${SiteID}/drives/${DriveID}/items/${DriveItemID}/sharepointIds


A possible answer is as follows:

JSON
 
{
    "siteId": "site-id",
    "webId": "web-id",
    "listId": "list-id",
    "listItemId": "ListItemID",
    "listItemUniqueId": "list-item-unique-id",
    "uniqueId": "drive-item-unique-id"
}


The answer is pretty self-explanatory. With the ListItemID, the values of the columns of the SharePoint list can now be read out for a single row (list item). With the next call, we can finally read the column values for a list item that represents the PDF we are looking for:

HTTP
 
https://graph.microsoft.com/v1.0/sites/${SiteID}/lists/${ListID}/items/${ListItemID}/fields


One possible answer could look like this:

JSON
 
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('siteID')/lists('listID')/items('listItemID')/fields",
    "Title": "Plan",
    "Status": "In Process",
    "Person": "Max Mustermann",
    "Created": "2024-09-13T10:20:30Z",
    "InCharge": "Lisa Müller",
    "Expire Date": "2024-09-20",   
}


The response to the request shows the respective column name and the corresponding column value for the special list element. The values of the columns can now be changed with a patch call via the same endpoint. All you have to do is define a JSON in the request body that contains the column name and the new column value. Let's assume we want to change the “Title” column. Then the JSON must look like this:

JSON
 
{
    "Title": "Plan2"
}


Conclusion

In this test case, we demonstrated how the Microsoft Graph API can be used to change the value of a specific column of a list item in a SharePoint list representing a PDF file. By clearly structuring the API calls, from authentication and retrieving IDs to querying and modifying fields, we were able to demonstrate the efficiency and flexibility of the API for managing SharePoint data. 

This process illustrates how SharePoint lists can be used as a centralized data structure within an organization to efficiently manage files and metadata. The API provides a powerful and programmatic way to access and modify this data, simplifying the workflow in modern, collaborative environments. With the successful modification of the list items, the integrity of the file is maintained and the changes are accurately reflected in SharePoint without affecting the file itself. This demonstrates that the API is a reliable and scalable solution for managing SharePoint content.

API Microsoft Teams PDF SharePoint Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • How Spring Boot Starters Integrate With Your Project
  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 7)
  • Scholcast: Generating Academic Paper Summaries With AI-Driven Audio
  • API and Security: From IT to Cyber

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!