Rest API examples - how to work retrieving list items from SharePoint with ContentType
![SharePoint 2016 Logo](https://markimarta.com/wp-content/uploads/2016/08/SharePoint-Logo_w492_h3121-150x150.jpg)
The queries to get all the list items, get list items with specific field values, get list items by ContentType Name. The most of the time I spend with the last one.
Get all the list items information and add it's ContentType:
Get all the list items information and add it's ContentType:
https://markimarta.com/sites/Euro2024/_api/web/lists/getByTitle('BookingObjects')/items?$select=Title,Id,ContentType/Name&$expand=ContentType
Get the list items and information about it's ContentType where Title == 'Hall 1'
https://markimarta.com/sites/Euro2024/_api/web/lists/getByTitle('BookingObjects')/items?$select=Title,Id,ContentType/Name&$expand=ContentType&$filter=Title%20eq%20%27Hall%201%27
Get the list items with specific ContentType by Name (filter by ContentType name):
https://markimarta.com/sites/Euro2024/_api/web/lists/getByTitle('BookingObjects')/items?$select=Title,Id,ContentType/Name&$expand=ContentType&$filter=ContentType%20eq%20%27ConferenceRoom%27
Get the list items with multiple specific ContentTypes by Name (filter by ContentType name - where ContentType eq 'ConferenceRoom' or eq 'Equipment'):
https://markimarta.com/sites/Euro2024/_api/web/lists/getByTitle('BookingObjects')/items?$select=Title,Id,ContentType/Name&$expand=ContentType&$filter=ContentType%20eq%20%27ConferenceRoom%27 or ContentType%20eq%20%27Equipment%27
For pnpjs the code is something like this:
const res: any = await this._sp.web.lists.getByTitle('BookingObjects').items.select('Id', 'Title', 'ContentType/Name').expand('ContentType').filter(`ContentType eq 'ConferenceRoom' or ContentType eq 'Equipment'`)();
Rest API request to determine if the time interval is free among the reservations for the booked item:
https://markimarta.com/sites/euro2024/_api/web/lists/GetByTitle('Reservation Events')/Items?$filter=((StartDate ge datetime'2023-07-13T10:00:00Z') and (EndDate le datetime'2023-07-20T14:00:00Z') and (StartDate ge datetime'2023-07-13T12:00:00Z') and (EndDate le datetime'2023-07-20T14:00:00Z')) and (BookObjectId eq 3)
Get all the items from the specific folder in SharePoint doclib
fetch("https://markimarta.com/sites/euro2024/bestboat/_api/Web/GetFolderByServerRelativeUrl('VoteLib/Team1')?$select=Name&$expand=Folders,Files", {headers:{'Accept':'application/json'}})
PNPJs query to get all the folders at the top level
sp.web.lists.getByTitle(this._objectList).rootFolder.folders()).filter( x=>x.Name !== 'Forms')
PNPJS query how to retrieve the items by the Author in SharePoint List. As a name I use Email
await this._sp.web.lists.getByTitle(this._voteList).items.select('Id', 'Title', 'Author/EMail', 'Author/Title').expand("Author").filter((Author/EMail eq '${userLogin}')
)()
or REST API query to retrieve the items by the Author in SharePoint List
https://markimarta.com/sites/euro2024/_api/web/lists/getByTitle('Votes')/items?$select=Title,Id,Author/EMail&$expand=Author