Accessing SharePoint Lookup Field Values with Microsoft Graph

Let's say I have an Orders list that has a lookup on a Customers list. The name of the lookup field is Customer and the target of the lookup is the Title field which stores the customer code.

image.png

image.png

Now I want to get data from the Orders list using Microsoft Graph. I can do so by making the following GET request. Expanding fields tells Microsoft Graph to include field values for each item in the response.

https://graph.microsoft.com/v1.0/sites/robwindsortest980.sharepoint.com:/sites/Demo:/lists/Orders/items?expand=fields

By default, the response will include the lookup Id for any lookup fields. In the case of the request above, the fields object for each item includes a property named CustomerLookupId which is the lookup Id for the Customer field.

image.png

But what if I want both the lookup Id and the lookup value? I can then modify the GET request to include a select with the expand for fields. To get the lookup value, the select should include the internal name of the field plus "LookupId". To get the lookup value, the select should include the internal name of the field.

https://graph.microsoft.com/v1.0/sites/robwindsortest980.sharepoint.com:/sites/Demo:/lists/Orders/items?expand=fields(select=id,Title,CustomerLookupId,Customer)

image.png

This is documented in the section in FieldValueSet resource | Properties.

image.png

Finally, what if I also wanted to get the values of other fields in the list that is the target of the lookup? In the case of the example I've been using, what if I wanted to get the the company name and the contact name for the customer associated with each order when requesting items from the Orders list? Unfortunately Microsoft Graph doesn't currently support this capability.

What I would need to do is first get all of the items from Customers list (selecting the id, Title, CompanyName, and ContactName field values), then get the data from the Orders list, then merge the two data sets using the Customer lookup Id as the key.

I would love to see an update to the Microsoft Graph that enabled us to get more than just the lookup Id and lookup value for SharePoint lookup fields. To that end, I posted the following to the Microsoft Graph Feedback Portal. Please upvote if you feel the same way I do about this functionality.

Add the ability to fully expand SharePoint lookup fields