Microsoft Graph API - upload to SharePoint with metadata

Simeonov, Hristo 0 Reputation points
2024-08-15T06:45:44.0033333+00:00

Hello everyone,

I reviewed many similar questions, but none were covering what I needed.

I have been trying to find a programmatic way of uploading a file to a SharePoint Site, which contains also some column data. The core goal that I have is to iterate through local files, which are mapped in a way to a CSV and then import them with the respective metadata into SP.

I have been looking around the MS documentation and tutorials and the closest thing I found is this - https://learn.microsoft.com/en-us/graph/api/listitem-create?view=graph-rest-1.0&tabs=java

Unfortunately this one is not exactly what I need.

Further I am able to upload a file to OneDrive, but there seems to be no documented way for a file in SharePoint. I would guess it should look like this somehow:

graphClient.sites().bySiteId(ApplicationProperties.siteId) then add or put.

Thank you!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,218 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yakun Huang-MSFT 6,255 Reputation points Microsoft Vendor
    2024-08-15T09:08:23.04+00:00

    Hi @Simeonov, Hristo

    There is a post with the same problem as yours. The solution is to upload file using the method in this document and then set the field value using the Update listItem method.

    See this link for more information:

    https://learn.microsoft.com/en-us/answers/questions/635048/how-to-upload-file-with-metadata-to-sharepoint-onl

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.