Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create SharePoint list item with lookup field with Microsoft Graph

I am trying to create list items with Microsoft Graph's new SharePoint endpoint. My URL is as follows: https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items

Calling this URL with POST, and a body like this:

{
    "fields": {
        "Title": "test",
    }
}

.. works! But if I include a lookup field, the lookup field is always empty. I have tried with

"{columnName}": "id",

"{columnName}": "id;#value",

"{columnName}": {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", //and others like this
    "Id": "id",
    "Value": "value",
}

"{columnName}": "value",
"{columnName}Id": "id",

None of these seems to work. Some give an error like "The request is malformed or incorrect.", others go through, but doesn't include the lookup field.

The documentation for this is scarce (if any), and I have found very little information on google (apart from someone asking the same question with no answers). Anyone that got this to work yet? Is it even possible?

like image 865
anderslooftharpoeth Avatar asked Oct 18 '22 07:10

anderslooftharpoeth


2 Answers

I have got this to work with people fields where the multiple selection option was DISABLED. So if you have a person field which allows one person only, the following works.

"{columnName}LookupId": id

Additionally, the id still needs to be the SP ID and not the graph user GUID. This ID changes from site to site.

like image 191
Anthony Graglia Avatar answered Oct 21 '22 08:10

Anthony Graglia


You need to add a lookup column in the following format

"Office": "London",
"OfficeLookupId", "16"

Where Office is the name of the column

like image 34
statto Avatar answered Oct 21 '22 09:10

statto