msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

New-MgSiteList Documentation Example is Incorrect

Open 12Knocksinna opened this issue 1 year ago • 5 comments

Describe the bug

The documentation for creating a new SharePoint site list in https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.sites/new-mgsitelist?view=graph-powershell-1.0&WT.mc_id=M365-MVP-9501 is incorrect and fails with a "New-MgSiteList_Create: Unable to determine type of provided column definition." The problem appears to have been around for a long time and people report being unable to use the cmdlet in Stack Overflow and other sites (here's an example: https://stackoverflow.com/questions/78712970/new-mgsitelist-unable-to-determine-type-of-provided-column-definition).

Expected behavior

The New-MgSiteList cmdlet should just work.

How to reproduce

Execute the New-MgSiteList example as documented. It won't work.

New-MgSiteList_Create: Line | 20 | New-MgSiteList -SiteId $site.Id -BodyParameter $params | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Unable to determine type of provided column definition

Status: 400 (BadRequest) ErrorCode: invalidRequest Date: 2024-08-12T16:27:30

Headers: Cache-Control : no-store, no-cache Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : b48f920f-198e-4504-bee3-9232c2c43850 client-request-id : f74ee450-f234-464c-932e-3dccf3ba495e x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Europe","Slice":"E","Ring":"4","ScaleUnit":"011","RoleInstance":"DB1PEPF000508A1"}} Date : Mon, 12 Aug 2024 16:27:30 GMT

SDK Version

2.21

Latest version known to work for scenario above?

Never, as far as I can see

Known Workarounds

Use the Graph request.

$Uri = ("https://graph.microsoft.com/v1.0/sites/{0}/Lists" -f $Site.Id) invoke-MgGraphRequest -Uri $Uri -Method POST -Body $NewListParameters

Name Value


@odata.context https://graph.microsoft.com/v1.0/$metadata#sites('office365itpros.sharepoint.com%2Cbf887032-2619-44a2-a8b0-2b9cfb1cf701%2Ce95c0fd7-42a6-4bd8-808f-e4683035ed6e')/l… description Contacts to add to User Address Book list {[template, contacts], [hidden, False], [contentTypesEnabled, False]} @odata.etag 4d117719-cd95-4047-b911-a1159446c949,10 createdDateTime 12/08/2024 16:31:59 lastModifiedDateTime 12/08/2024 16:32:00 createdBy {[user, System.Collections.Hashtable]} parentReference {[siteId, office365itpros.sharepoint.com,bf887032-2619-44a2-a8b0-2b9cfb1cf701,e95c0fd7-42a6-4bd8-808f-e4683035ed6e]} webUrl https://office365itpros.com/sites/Office365News/Lists/Organizational%20Contacts name Organizational Contacts id 4d117719-cd95-4047-b911-a1159446c949 eTag 4d117719-cd95-4047-b911-a1159446c949,10 displayName Organizational Contacts

Debug output

Click to expand log ```

New-MgSiteList -SiteId $site.Id -BodyParameter $params -debug DEBUG: [CmdletBeginProcessing]: - New-MgSiteList begin processing with parameterSet 'Create'. DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'. DEBUG: [Authentication]: - Scopes: [AccessReview.Read.All, Agreement.Read.All, Analytics.Read, APIConnectors.Read.All, Application.Read.All, Application.ReadWrite.All, AppRoleAssignment.ReadWrite.All, AuditLog.Read.All, AuditLogsQuery.Read.All, Calendars.Read, Calendars.ReadWrite, Channel.ReadBasic.All, ChannelMessage.Read.All, ChannelMessage.ReadWrite, ChannelMessage.Send, ChannelSettings.Read.All, ChannelSettings.ReadWrite.All, Chat.Create, Chat.ManageDeletion.All, Chat.ReadWrite, Community.ReadWrite.All, Contacts.ReadWrite, CrossTenantUserProfileSharing.Read, CrossTenantUserProfileSharing.Read.All, DelegatedPermissionGrant.ReadWrite.All, DeviceManagementManagedDevices.Read.All, Directory.AccessAsUser.All, Directory.Read.All, Directory.ReadWrite.All, DirectoryRecommendations.Read.All, Domain.Read.All, eDiscovery.Read.All, email, EntitlementManagement.Read.All, Group.Read.All, Group.ReadWrite.All, GroupMember.Read.All, GroupMember.ReadWrite.All, IdentityProvider.Read.All, IdentityProvider.ReadWrite.All, IdentityRiskyUser.Read.All, IdentityRiskyUser.ReadWrite.All, IdentityUserFlow.Read.All, InformationProtectionPolicy.Read, Mail.Read, Mail.ReadWrite, Mail.Send, Mail.Send.Shared, MailboxSettings.ReadWrite, Notes.Create, OnlineMeetingArtifact.Read.All, OnlineMeetings.Read, openid, Organization.Read.All, PeopleSettings.Read.All, PeopleSettings.ReadWrite.All, Place.Read.All, Policy.Read.All, Policy.Read.PermissionGrant, Policy.ReadWrite.ApplicationConfiguration, Policy.ReadWrite.AuthenticationMethod, Policy.ReadWrite.ConditionalAccess, POP.AccessAsUser.All, PrivilegedAccess.Read.AzureAD, PrivilegedAccess.Read.AzureResources, profile, RecordsManagement.Read.All, Reports.Read.All, ReportSettings.ReadWrite.All, RoleAssignmentSchedule.Read.Directory, RoleAssignmentSchedule.ReadWrite.Directory, RoleEligibilitySchedule.Read.Directory, RoleManagement.Read.All, RoleManagement.Read.Directory, SecurityActions.ReadWrite.All, SecurityEvents.Read.All, SecurityEvents.ReadWrite.All, ServiceHealth.Read.All, ServiceMessage.Read.All, SharePointTenantSettings.ReadWrite.All, Sites.FullControl.All, Sites.Manage.All, Sites.Read.All, Sites.ReadWrite.All, Tasks.Read, Tasks.ReadWrite, Team.ReadBasic.All, TeamMember.Read.All, TeamSettings.Read.All, TeamsTab.Read.All, TeamworkTag.ReadWrite, User.Read, User.Read.All, User.ReadBasic.All, User.ReadWrite, User.ReadWrite.All, UserActivity.ReadWrite.CreatedByApp, UserAuthenticationMethod.Read.All, UserAuthenticationMethod.ReadWrite.All, User-ConvertToInternal.ReadWrite.All, VirtualEvent.Read, WindowsUpdates.Read.All].

Confirm Are you sure you want to perform this action? Performing the operation "New-MgSiteList_Create" on target "Call remote 'POST /sites/{site-id}/lists' operation". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y DEBUG: ============================ HTTP REQUEST ============================

HTTP Method: POST

Absolute Uri: https://graph.microsoft.com/v1.0/sites/office365itpros.sharepoint.com%2Cbf887032-2619-44a2-a8b0-2b9cfb1cf701%2Ce95c0fd7-42a6-4bd8-808f-e4683035ed6e/lists

Headers: FeatureFlag : 00000043 Cache-Control : no-store, no-cache User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22631; en-IE),PowerShell/7.4.4 Accept-Encoding : gzip SdkVersion : graph-powershell/2.21.0 client-request-id : 0f58e2ac-bb5d-4080-8463-024ac792b078

Body: { "displayName": "Books", "columns": [ { "name": "Author" }, { "name": "PageCount" } ], "list": { "template": "genericList" } }

DEBUG: ============================ HTTP RESPONSE ============================

Status Code: BadRequest

Headers: Cache-Control : no-store, no-cache Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : 153b3898-6bad-4290-b66a-4c734e1514e2 client-request-id : 0f58e2ac-bb5d-4080-8463-024ac792b078 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Europe","Slice":"E","Ring":"4","ScaleUnit":"011","RoleInstance":"DB1PEPF00043F22"}} Date : Mon, 12 Aug 2024 16:29:09 GMT

Body: { "error": { "code": "invalidRequest", "message": "Unable to determine type of provided column definition", "innerError": { "date": "2024-08-12T16:29:09", "request-id": "153b3898-6bad-4290-b66a-4c734e1514e2", "client-request-id": "0f58e2ac-bb5d-4080-8463-024ac792b078" } } }

New-MgSiteList_Create: Unable to determine type of provided column definition

Status: 400 (BadRequest) ErrorCode: invalidRequest Date: 2024-08-12T16:29:09

Headers: Cache-Control : no-store, no-cache Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : 153b3898-6bad-4290-b66a-4c734e1514e2 client-request-id : 0f58e2ac-bb5d-4080-8463-024ac792b078 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Europe","Slice":"E","Ring":"4","ScaleUnit":"011","RoleInstance":"DB1PEPF00043F22"}} Date : Mon, 12 Aug 2024 16:29:09 GMT

DEBUG: [CmdletEndProcessing]: - New-MgSiteList end processing.

Configuration

No response

Other information

No response

12Knocksinna avatar Aug 12 '24 16:08 12Knocksinna

Hi @12Knocksinna thank you for raising this issue. After investigations we realized the request body formulated by the SDKs removes any empty Json object. In comparison to the example provided (See first image below) the empty text and number json objects inside the columns list is missing, yet the API treats them as mandatory properties to be included in the columns definition collection. image

The work-around for this is to either use Invoke-MgGraphRequest if you prefer copying the example as it is or ensure that the text and number Json objects are not empty as per the documentation here https://learn.microsoft.com/en-us/graph/api/resources/textcolumn?view=graph-rest-1.0 and here https://learn.microsoft.com/en-us/graph/api/resources/numbercolumn?view=graph-rest-1.0. I have tried it, and it works as expected. (See image below). image

timayabi2020 avatar Aug 14 '24 08:08 timayabi2020

After doing further checks, this is both a service and documentation issue because by design the SDK does not serialize empty Json objects. Both offline and online help files also derive examples from http examples in the API reference documentation. https://learn.microsoft.com/graph/api/list-create?view=graph-rest-1.0. Unfortunately, we are not best placed to give reasons as to why the service accepts empty json objects and gives an error if the object is completely removed from the request body. Kindly raise an issue here https://developer.microsoft.com/en-us/graph/support so that the API owner can respond to it.

timayabi2020 avatar Aug 21 '24 14:08 timayabi2020

Given that one Microsoft group has already reviewed and verified that the issue exists, why don't you simply transfer this problem to the API owner internally? I'm struggling to understand how me doing this would be anyway more efficient or productive.

12Knocksinna avatar Aug 21 '24 15:08 12Knocksinna

@msewaweru @SteveMutungi254 kindly assist with follow up on this issue

timayabi2020 avatar Aug 22 '24 06:08 timayabi2020

@CarolKigoonya : Kindly liaise with the workload owner.

SteveMutungi254 avatar Aug 26 '24 12:08 SteveMutungi254

Issue closed by this PR https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/3224.

timayabi2020 avatar Mar 18 '25 08:03 timayabi2020