Table of contents
- Hub site and its children
- Getting a site id
- Site columns
- Lists
- Create list or modify list settings
- Deleting a list
- List fields
- Create list fields
- Delete list columns
- Content types
- Get all list content types
- Create list content type
- Modify existing list content type
- Get content type fields
- Views
- Get list views
- List view fields
Hub site and its children
//first get the hubsiteid
Method: GET
Uri: /_api/site?$select=IsHubSite,HubSiteId
Result: body('Send_an_HTTP_request_to_SharePoint_-_Hub_Site_Id')?['d']?['HubSiteId']
//use result in another http action, by default the api will return a paged array. Using the top parameters gives you all sites in a single array. The service limit for assigning children to a hub is 500.
_api/v2.1/sites?$filter=sharepointIds/hubSiteId eq 'HUBSITEID'&$top=500
Getting a site id
This return an id property that contains three parts separated by commas. The second value is the site id.
_api/v2.0/sites/tenant.sharepoint.com:/sites/Training:/
Site columns
Method: GET
Uri: _api/web/fields
Result: body('ACTIONNAME')?['d']?['results']
Lists
Something to look out for is the BaseType, 0 = List, 1 = Library
Sadly, this endpoint does not directly support filtering. You could use something like “GetByTitle(’SitePages’)” instead.
Method: GET
//all lists
Uri: _api/web/lists
//specific list
_api/web/lists('LIST GUID')
Uri:
Headers:
{
"accept": "application/json;odata=verbose",
"content-type ": "application/json;odata=verbose"
}
Result: body('ACTIONNAME')?['d']?['results']
Create list or modify list settings
All list settings can be found here: SP.List object | Microsoft Learn
BaseTemplate 100 = List, 101 = Library
Adding these exact headers is very important!
//Create list
Method: POST
Uri: _api/web/lists
Headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose"
}
Body:
{
"__metadata": {
"type": "SP.List"
},
"AllowContentTypes": true,
"BaseTemplate": 100,
"ContentTypesEnabled": true,
"Description": "My list description",
"Title": "Test"
}
//Modify list settings
Method: POST
Uri: _api/web/lists('LIST GUID')
Headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"If-Match": "*",
"X-HTTP-Method": "MERGE"
}
Body:
{
"__metadata": {
"type": "SP.List"
},
"AllowContentTypes": true,
"BaseTemplate": 100,
"ContentTypesEnabled": true,
"Description": "My list description",
"Title": "Test"
}
Deleting a list
Method: DELETE
Uri: _api/web/lists('LISTGUID')
Headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose"
}
List fields
Something to look out for is the StaticName property. This shows the fields internal name.
Method: GET
Uri: _api/web/lists(guid'LISTGUID')/fields
//also works with select and filter
_api/web/lists(guid'LISTGUID')/fields?$select=__metadata,Title,FieldTypeKind,Required,EnforceUniqueValues,StaticName,Hidden&$filter=Hidden eq false
_api/web/lists/getByTitle('My list')/fields?$select=id,Title
Result: body('ACTIONNAME')?['d']?['results']
Create list fields
Method: POST
Uri: _api/web/lists(guid'LISTGUID')/fields
Headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose"
}
Body:
{
"__metadata":
{
"type": "SP.Field"
},
"FieldTypeKind": 2,
"Title":"DisplayName",
"StaticName":"InternalName",
"Required": true,
//Datetime column (DateOnly = 0, DateTime = 1)
"DisplayFormat": 0,
//Choice values or column formatting
"SchemaXml": "Xml",
"ReadOnlyField":false
}
Delete list columns
Sometimes the action will return an error saying that the field cannot be found, this is wrong. If you can see in the UI, its there. In that case you will need to use the field id instead of the title. To do that
Method: POST
Uri: _api/web/lists/getByTitle('My list')/fields/getbytitle('My column')
With field id: _api/web/lists/getByTitle('Planner Kanban')/fields/getbyid('field guid')
Headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTP-Method": "DELETE"
}
Content types
Get all list content types
Supports: Select, Filter
Method: GET
Uri: _api/web/Lists('LISTGUID')/ContentTypes
Result: body('ACTIONNAME')?['d']?['results']
Create list content type
Method: POST
Uri: _api/web/Lists(guid'LISTGUID')/ContentTypes
Body:
{
"__metadata": {
"type": "SP.ContentType"
},
"Name": "New Content Type",
"Description": "New Content Type Description",
"Group": "Custom Content Type Group"
}
Modify existing list content type
Method: POST
Uri: _api/web/Lists('LISTGUID')/ContentTypes('CONTENTTYPEID')
Headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"If-Match": "*",
"X-HTTP-Method": "MERGE"
}
Body:
{
"__metadata": {
"type": "SP.ContentType"
},
"Name":"New Name"
"NewFormClientSideComponentId": ""
}
Get content type fields
This would be part of a loop based on listing the content types.
Method: GET
Uri: _api/web/Lists('LIST GUID')/ContentTypes('item()?['StringId']}')/fields
Result: body('ACTIONNAME')?['d']?['results']
Views
Get list views
Method: GET
Uri: _api/web/lists(guid'LISTGUID')/Views
Result: body('ACTIONNAME')?['d']?['results']
//to get the default view and its id
Uri: _api/web/lists(guid'LISTGUID')/Views?$filter=DefaultView eq true
Result: first(body('ACTIONNAME')?['d']?['results'])?['Id']
List view fields
This would be a part of a loop based on listing the views.
Method: GET
Uri: _api/web/lists(guid'LISTGUID')/Views(guid'item()?['Id']')/ViewFields
Result: body('ACTIONNAME')?['d']?['results']
Thanks for reading! 💕