简体   繁体   中英

Unable to fetch lookup field values using REST api

I am using REST api to fetch data from a SharePoint list.

I am able to get the lookup fields data using this query: requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department .

However when I use this query requestUri = "/_api/lists/GetByTitle('Data')/items(6)" or this query requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department&$filter=ID eq 6" I am not getting the data from the lookup fields.

What could be going wrong here?

I tested with the endpoint, it works:

/_api/web/lists/GetByTitle('ListName')/items(1)?$select=ID,Title,Department/Title&$expand=Department

在此处输入图像描述

Compared the url with yours in original question, only append web behind /_api, it should be working.

The issue was found.

Figured out that I was fetching an item for which all the lookup fields were blank.

I fetched another item, and data was returned as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM