Microsoft Graph API - Sharepoint list unable to POST/PATCH sharepoint list items using client credentials, GET/DELETE works fine. Invalid request error.

Starlord 1 Reputation point
2022-12-02T14:42:03.507+00:00

Unable to use Microsoft Graph API to create or update SharePoint list items with client credentials access token, I get the following error, I'm able to successfully call GET and DELETE calls with the same access tokens for the same site/list. additionally I'm able to call all methods GET/POST/UPDATE/DELETE for the same site/list using the user generated access token.
266702-image.png

For my use case I need to able to create/update list items (with out a user,)so followed this article - https://learn.microsoft.com/en-us/graph/auth-v2-service and additionally granted app roles, which are showing up in the token

266655-image.png

can't seem to find any documentation on what exactly I'm missing. Here is the documentation I'm following https://learn.microsoft.com/en-us/graph/api/listitem-create?view=graph-rest-1.0&tabs=http & I've tried using the .net graph client SDK as well and I get the same error message for both POST/PATCH requests.

266609-image.png

Any help on how to successfully request POST/PATCH to create sharepoint list using client credential token would be very helpful,

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,645 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,675 questions
{count} votes

2 answers

Sort by: Most helpful
  1. HarmeetSingh7172 4,811 Reputation points
    2022-12-15T15:06:11.367+00:00

    Hello @Starlord

    Thanks for reaching out!

    Referring the Graph API documentation you shared, I'm able to Create/Update SharePoint List Item with Client-credential Token.

    Please find below sample request along with screenshots for reference:

    Sample request:

    POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items  
    Content-Type: application/json  
      
    {  
      "fields": {  
        "Title": "Widget",  
        "Color": "Purple",  
        "Weight": 32  
      }  
    }  
    

    271048-createlistitem1.png

    Results:

    271070-ui1.png

    Update List Item:

    Sample request body:

    PATCH https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}/fields  
    Content-Type: application/json  
      
    {  
        "Color": "Fuchsia",  
        "Quantity": 934  
    }  
    

    271141-patch1.png

    Results:

    271038-ui20.png

    NOTE: Please use only valid Column Names while executing both Operations (CREATE/PATCH).

    References:
    https://learn.microsoft.com/en-us/graph/api/listitem-create?view=graph-rest-1.0&tabs=http
    https://learn.microsoft.com/en-us/graph/api/listitem-update?view=graph-rest-1.0&tabs=http

    Hope this helps.

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


  2. Abhijit Pal 0 Reputation points
    2023-10-13T18:17:58.3433333+00:00

    @Tong Zhang_MSFT @HarmeetSingh7172 I wish to update description/nam/displayName of the list using Graph API and facing the same issue while making PUT/PATCH request

    0 comments No comments