restsharepointspfx

Fetch sharepoint list by its title


I have created a field/list column in Sharepoint list called 'Negative_TC_Count', when I try to fetch using REST call it returns below error

_api/web/lists/getByTitle('Tracker2023')/items?Negative_TC_Count&$expand=AttachmentFiles&$top=5000&$orderby=Created%20desc

Error:-

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <m:code>-1, Microsoft.SharePoint.SPException</m:code> <m:message xml:lang="en-US">The field or property 'Negative_TC_Count' does not exist.</m:message> </m:error>


Solution

  • As mentioned by @RobWindsor, you have to use the $select in SharePoint REST API endpoint to select specific columns from your SharePoint list. Like:

    <site-url>/_api/web/lists/getByTitle('Tracker2023')/items?$select=Title,Negative_TC_Count&$expand=AttachmentFiles&$top=5000&$orderby=Created desc
    

    Considering Negative_TC_Count is the correct internal name of your SharePoint list column.

    Also, one important thing you have to consider while writing the SharePoint REST API request endpoint is you have to use the internal names of your SharePoint list columns.

    Sometimes display name of columns and internal name of columns can be different when you use the special characters in column names while creating the columns.

    You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?