Create custom column - Access Denied

Marskar, Tore 20 Reputation points
2023-10-23T06:25:28.6433333+00:00

Hi

Developing an external app logging on to Teams(Sharepoint). Get an error when I try to create a custom column. Usually the ODataError object will list up the API permission I'm missing but this time around I only get 'Access Denied'. Anyone knows what permission my application is missing?

 

Cheers
Tore

 

 

var columnDef = new Microsoft.Graph.Models.ColumnDefinition
{
Description = "test1",
EnforceUniqueValues = false,
Hidden = false,
Indexed = false,
Name = "Title1",
Text = new TextColumn
{
AllowMultipleLines = false,
AppendChangesToExistingText = false,
LinesForEditing = 0,
MaxLength = 255,
},
};

try
{
// Returns 43 list columns
var colums = await _graphClient.Drives[item.ParentReference.DriveId].List.Columns.GetAsync();
//Throws Access Denied error
var result = await _graphClient.Drives[item.ParentReference.DriveId].List.Columns.PostAsync(columnDef);
}

catch (ODataError err)
{
//Access Denied
}

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,448 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,810 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 40,311 Reputation points
    2023-10-23T10:00:02.8366667+00:00

    Hi @Marskar, Tore

    You should create column definitions in a site. Here are the permissions you need:

    User's image

    Code snippet:

    var graphClient = new GraphServiceClient(requestAdapter);
    
    var requestBody = new ColumnDefinition
    {
    	Description = "test2",
    	EnforceUniqueValues = false,
    	Hidden = false,
    	Indexed = false,
    	Name = "Title2",
    	Text = new TextColumn
    	{
    		AllowMultipleLines = false,
    		AppendChangesToExistingText = false,
    		LinesForEditing = 0,
    		MaxLength = 255,
    	},
    };
    var result = await graphClient.Sites["{site-id}"].Columns.PostAsync(requestBody);
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful