Search Posts

SharePoint Online get all items with fields specified by view

I am not sure i am correct or not. There is no /_api/web/lists/GetByTitle(‘your list’)/View/getbytitle(‘your view’)/items restful api for SharePoint online. So to get the items with fields that specificed by a view, you need these steps:

  1. Call “/_api/web/lists/GetByTitle(‘your list’)/fields” to read all fields and save all “InternalName” and “FieldTypeKind”
  2. Call “/_api/web/lists/GetByTitle(‘your list’)/View/getbytitle(‘your view’)/ViewFields” to read all fields from a specific view, but this will just give you the field name
  3. Construct the query and send to “/_api/web/lists/GetByTitle(‘your list’)/items”, if the field’s FieldTypeKind = 20, that mean it is a “User” field, you need to send “expand” to the query, for example:

my view just have two fields : ID and LinkFilename, because LinkFilename is a computed field, so the query would be

/_api/web/lists/GetByTitle(‘your list’)/items?$select=ID,LinkFilename/Title&expand=LinkFilename

The key parts are highlighted in red

Remarks : We don’t need to pass “select=ID” to the query, because if you don’t, SharePoint restful api will still returning you the ID. If you do so, you got duplicated fields with different case sensitive:

{
"__metadata": {
"id": "d712b553-2735-404e-94e1-91f360127947",
"uri": "https://quantr.sharepoint.com/test/_api/Web/Lists(guid\u00275d9df756-8067-4599-b1cc-fc9ca610c4fe\u0027)/Items(11)",
"etag": "\"2\"",
"type": "SP.Data.Doclib1Item"
},
"Id": 11,
"ID": 11,
"LinkFilename": "mRk.EOo9ry_3HaqpPk5wkA.jpg"
}

Peter.

Leave a Reply

Your email address will not be published. Required fields are marked *