Updating a Lookup Field in SharePoint via Microsoft Graph API Results in "invalidRequest" Error

65 Views Asked by At

I'm working with the Microsoft Graph API to update the fields of a SharePoint list-item. Updating regular fields works as expected, using the following PATCH request:

PATCH https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}/fields

{
  "RegularField": "new_value"
}

However, when attempting to update a lookup field using the ID of the item it should refer to, I encounter an "invalidRequest" error. Here's the request body I've tried:

{
  "LookupField": [
    {
      "id": "742"
    }
  ]
}

This results in the following error response:

{
  "error": {
    "code": "invalidRequest",
    "message": "Invalid request",
    "innerError": {
      "date": "2024-02-04T09:15:57",
      "request-id": "...",
      "client-request-id": "..."
    }
  }
}

I've also attempted to use a different request body format, directly referencing the lookup ID:

{
  "LookupFieldLookupId": "742"
}

Unfortunately, this resulted in the same "invalidRequest" error. I've confirmed that the site-id, list-id, item-id, and authorization are correct since I can successfully update other fields.

Questions:

  1. What is the correct format for updating a lookup field in SharePoint using the Microsoft Graph API?
  2. Is there a specific property name or format I should be using that differs from my current approach?

Any insights or guidance on how to correctly update a lookup field would be greatly appreciated.

1

There are 1 best solutions below

0
cb0008 On

user2250152's question helped me to find the answer. Changing the requestbody allowed me to update the lookupfield:

{
  "LookupFieldLookupId": [ "742" ],
  "[email protected]": "Collection(Edm.Int32)"
}