Create a new list
Article
02/23/2022
3 minutes to read
12 contributors
In this article
Namespace: microsoft.graph
Create a new list in a site .
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Sites.Manage.All
Delegated (personal Microsoft account)
Not supported.
Application
Sites.Manage.All
HTTP request
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists
Name
Description
Authorization
Bearer {token}. Required.
Content-Type
application/json. Required.
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 unspecified, the list defaults to the genericList
template, which includes a Title column.
POST /sites/{site-id}/lists
Content-Type: application/json
{
"displayName": "Books",
"columns": [
{
"name": "Author",
"text": { }
},
{
"name": "PageCount",
"number": { }
}
],
"list": {
"template": "genericList"
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var list = new List
{
DisplayName = "Books",
Columns = new ListColumnsCollectionPage()
{
new ColumnDefinition
{
Name = "Author",
Text = new TextColumn
{
}
},
new ColumnDefinition
{
Name = "PageCount",
Number = new NumberColumn
{
}
}
},
ListInfo = new ListInfo
{
Template = "genericList"
}
};
await graphClient.Sites["{site-id}"].Lists
.Request()
.AddAsync(list);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
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')
.post(list);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/sites/{site-id}/lists"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphList *list = [[MSGraphList alloc] init];
[list setDisplayName:@"Books"];
NSMutableArray *columnsList = [[NSMutableArray alloc] init];
MSGraphColumnDefinition *columns = [[MSGraphColumnDefinition alloc] init];
[columns setName:@"Author"];
MSGraphTextColumn *text = [[MSGraphTextColumn alloc] init];
[columns setText:text];
[columnsList addObject: columns];
MSGraphColumnDefinition *columns = [[MSGraphColumnDefinition alloc] init];
[columns setName:@"PageCount"];
MSGraphNumberColumn *number = [[MSGraphNumberColumn alloc] init];
[columns setNumber:number];
[columnsList addObject: columns];
[list setColumns:columnsList];
MSGraphListInfo *list = [[MSGraphListInfo alloc] init];
[list setTemplate:@"genericList"];
[list setList:list];
NSError *error;
NSData *listData = [list getSerializedDataWithError:&error];
[urlRequest setHTTPBody:listData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
List list = new List();
list.displayName = "Books";
LinkedList<ColumnDefinition> columnsList = new LinkedList<ColumnDefinition>();
ColumnDefinition columns = new ColumnDefinition();
columns.name = "Author";
TextColumn text = new TextColumn();
columns.text = text;
columnsList.add(columns);
ColumnDefinition columns1 = new ColumnDefinition();
columns1.name = "PageCount";
NumberColumn number = new NumberColumn();
columns1.number = number;
columnsList.add(columns1);
ColumnDefinitionCollectionResponse columnDefinitionCollectionResponse = new ColumnDefinitionCollectionResponse();
columnDefinitionCollectionResponse.value = columnsList;
ColumnDefinitionCollectionPage columnDefinitionCollectionPage = new ColumnDefinitionCollectionPage(columnDefinitionCollectionResponse, null);
list.columns = columnDefinitionCollectionPage;
ListInfo list = new ListInfo();
list.template = "genericList";
list.list = list;
graphClient.sites("{site-id}").lists()
.buildRequest()
.post(list);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewList()
displayName := "Books"
requestBody.SetDisplayName(&displayName)
requestBody.SetColumns( []ColumnDefinition {
msgraphsdk.NewColumnDefinition(),
SetAdditionalData(map[string]interface{}{
"name": "Author",
}
msgraphsdk.NewColumnDefinition(),
SetAdditionalData(map[string]interface{}{
"name": "PageCount",
}
}
list := msgraphsdk.NewListInfo()
requestBody.SetList(list)
template := "genericList"
list.SetTemplate(&template)
siteId := "site-id"
result, err := graphClient.SitesById(&siteId).Lists().Post(requestBody)
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Import-Module Microsoft.Graph.Sites
$params = @{
DisplayName = "Books"
Columns = @(
@{
Name = "Author"
Text = @{
}
}
@{
Name = "PageCount"
Number = @{
}
}
)
List = @{
Template = "genericList"
}
}
New-MgSiteList -SiteId $siteId -BodyParameter $params
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
The following is an example of 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"
}
}
}