Namespace: microsoft.graph
Important
APIs under the /beta
version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Create a new list in a site.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
✅ |
✅ |
✅ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permission type |
Least privileged permissions |
Higher privileged permissions |
Delegated (work or school account) |
Sites.Manage.All |
Not available. |
Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
Application |
Sites.Manage.All |
Sites.ReadWrite.All |
HTTP request
POST /sites/{site-id}/lists
Request body
In the request body, supply a JSON representation of a list object.
Response
If successful, this method returns a 201 Created
response code and a list object in the response body.
Examples
Request
The following is an example of how to create a new generic list.
Note: Custom columns are optional.
In addition to any columns specified here, new lists are created with columns defined in the referenced template.
If the list facet or template is not specified, the list defaults to the genericList
template, which includes a Title column.
POST https://graph.microsoft.com/beta/sites/{site-id}/lists
Content-Type: application/json
{
"displayName": "Books",
"columns": [
{
"name": "Author",
"text": { }
},
{
"name": "PageCount",
"number": { }
}
],
"list": {
"template": "genericList"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new List
{
DisplayName = "Books",
Columns = new List<ColumnDefinition>
{
new ColumnDefinition
{
Name = "Author",
Text = new TextColumn
{
},
},
new ColumnDefinition
{
Name = "PageCount",
Number = new NumberColumn
{
},
},
},
List = new ListInfo
{
Template = "genericList",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Sites["{site-id}"].Lists.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewList()
displayName := "Books"
requestBody.SetDisplayName(&displayName)
columnDefinition := graphmodels.NewColumnDefinition()
name := "Author"
columnDefinition.SetName(&name)
text := graphmodels.NewTextColumn()
columnDefinition.SetText(text)
columnDefinition1 := graphmodels.NewColumnDefinition()
name := "PageCount"
columnDefinition1.SetName(&name)
number := graphmodels.NewNumberColumn()
columnDefinition1.SetNumber(number)
columns := []graphmodels.ColumnDefinitionable {
columnDefinition,
columnDefinition1,
}
requestBody.SetColumns(columns)
list := graphmodels.NewListInfo()
template := "genericList"
list.SetTemplate(&template)
requestBody.SetList(list)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
lists, err := graphClient.Sites().BySiteId("site-id").Lists().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
List list = new List();
list.setDisplayName("Books");
LinkedList<ColumnDefinition> columns = new LinkedList<ColumnDefinition>();
ColumnDefinition columnDefinition = new ColumnDefinition();
columnDefinition.setName("Author");
TextColumn text = new TextColumn();
columnDefinition.setText(text);
columns.add(columnDefinition);
ColumnDefinition columnDefinition1 = new ColumnDefinition();
columnDefinition1.setName("PageCount");
NumberColumn number = new NumberColumn();
columnDefinition1.setNumber(number);
columns.add(columnDefinition1);
list.setColumns(columns);
ListInfo list1 = new ListInfo();
list1.setTemplate("genericList");
list.setList(list1);
List result = graphClient.sites().bySiteId("{site-id}").lists().post(list);
const options = {
authProvider,
};
const client = Client.init(options);
const list = {
displayName: 'Books',
columns: [
{
name: 'Author',
text: { }
},
{
name: 'PageCount',
number: { }
}
],
list: {
template: 'genericList'
}
};
await client.api('/sites/{site-id}/lists')
.version('beta')
.post(list);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\List;
use Microsoft\Graph\Beta\Generated\Models\ColumnDefinition;
use Microsoft\Graph\Beta\Generated\Models\TextColumn;
use Microsoft\Graph\Beta\Generated\Models\NumberColumn;
use Microsoft\Graph\Beta\Generated\Models\ListInfo;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new EscapedList();
$requestBody->setDisplayName('Books');
$columnsColumnDefinition1 = new ColumnDefinition();
$columnsColumnDefinition1->setName('Author');
$columnsColumnDefinition1Text = new TextColumn();
$columnsColumnDefinition1->setText($columnsColumnDefinition1Text);
$columnsArray []= $columnsColumnDefinition1;
$columnsColumnDefinition2 = new ColumnDefinition();
$columnsColumnDefinition2->setName('PageCount');
$columnsColumnDefinition2Number = new NumberColumn();
$columnsColumnDefinition2->setNumber($columnsColumnDefinition2Number);
$columnsArray []= $columnsColumnDefinition2;
$requestBody->setColumns($columnsArray);
$list = new ListInfo();
$list->setTemplate('genericList');
$requestBody->setEscapedList($list);
$result = $graphServiceClient->sites()->bySiteId('site-id')->lists()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Sites
$params = @{
displayName = "Books"
columns = @(
@{
name = "Author"
text = @{
}
}
@{
name = "PageCount"
number = @{
}
}
)
list = @{
template = "genericList"
}
}
New-MgBetaSiteList -SiteId $siteId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.list import List
from msgraph_beta.generated.models.column_definition import ColumnDefinition
from msgraph_beta.generated.models.text_column import TextColumn
from msgraph_beta.generated.models.number_column import NumberColumn
from msgraph_beta.generated.models.list_info import ListInfo
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = List_(
display_name = "Books",
columns = [
ColumnDefinition(
name = "Author",
text = TextColumn(
),
),
ColumnDefinition(
name = "PageCount",
number = NumberColumn(
),
),
],
list = ListInfo(
template = "genericList",
),
)
result = await graph_client.sites.by_site_id('site-id').lists.post(request_body)
Response
The following example shows the response.
Note: The response object is truncated for clarity. Default properties will be returned from the actual call.
HTTP/1.1 201 Created
Content-type: application/json
{
"id": "22e03ef3-6ef4-424d-a1d3-92a337807c30",
"createdDateTime": "2017-04-30T01:21:00Z",
"createdBy": {
"user": {
"displayName": "Ryan Gregg",
"id": "8606e4d5-d582-4f5f-aeba-7d7c18b20cfd"
}
},
"lastModifiedDateTime": "2016-08-30T08:26:00Z",
"lastModifiedBy": {
"user": {
"displayName": "Ryan Gregg",
"id": "8606e4d5-d582-4f5f-aeba-7d7c18b20cfd"
}
}
}