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:
- What is the correct format for updating a lookup field in SharePoint using the Microsoft Graph API?
- 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.
user2250152's question helped me to find the answer. Changing the requestbody allowed me to update the lookupfield: