Skip to content

Issue with New-MgSiteListItem #1185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
desmay opened this issue Mar 31, 2022 · 15 comments · Fixed by #1303
Closed

Issue with New-MgSiteListItem #1185

desmay opened this issue Mar 31, 2022 · 15 comments · Fixed by #1303
Assignees

Comments

@desmay
Copy link

desmay commented Mar 31, 2022

I updated my workstation to Microsoft.Graph.Sites to version 1.93. and the following command is failing.
New-MgSiteListItem -listid $logListId -SiteId $siteId -Fields @{Title = "Test"}

If I rollback to version 1.9.2 I have no issues and can create list items with code above.

@ghost ghost added the ToTriage label Mar 31, 2022
@peombwa
Copy link
Member

peombwa commented Mar 31, 2022

@desmay, what error message are you getting? Please share the complete output of New-MgSiteListItem -listid $logListId -SiteId $siteId -Fields @{Title = "Test"} -Debug.

@desmay
Copy link
Author

desmay commented Apr 1, 2022

PS C:\Users\desmay> New-MgSiteListItem -listid $logListId -SiteId $siteId -Fields $hash -debug
DEBUG: [CmdletBeginProcessing]: - New-MgSiteListItem begin processing with parameterSet 'CreateExpanded1'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', AuthProviderType: 'ClientCredentialProvider', ContextScope: 'Process', AppName: 'm365groupaudit'.
DEBUG: [Authentication]: - Scopes: [Sites.Selected, Group.Read.All, Directory.Read.All, User.Read.All, GroupMember.Read.All, Files.Read.All].

Confirm
Are you sure you want to perform this action?
Performing the operation "New-MgSiteListItem_CreateExpanded1" on target "Call remote 'SitesListsCreateItems1'
operation".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
POST

Absolute Uri:
https://graph.microsoft.com/v1.0/sites/f8bc881b-f7af-4f34-9b18-d0e0f70712e6/lists/689d3102-a76e-459b-b61a-686051f4fe16/items

Headers:
SdkVersion : graph-powershell/1.9.3,Graph-dotnet-1.25.1
FeatureFlag : 00000047
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22000; en-US),PowerShell/7.2.2,New-MgSiteListItem_CreateExpanded1
Accept-Encoding : gzip

Body:
{
"fields": {
"title": "Something"
}
}

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

Status Code:
BadRequest

Headers:
Cache-Control : no-store, no-cache
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : add66644-a176-4fc1-9ba7-d4f9f50adc31
client-request-id : add66644-a176-4fc1-9ba7-d4f9f50adc31
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"South Central US","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"SA2PEPF00000569"}}
Date : Fri, 01 Apr 2022 11:22:41 GMT

Body:
{
"error": {
"code": "invalidRequest",
"message": "Field 'title' is not recognized",
"innerError": {
"date": "2022-04-01T11:22:41",
"request-id": "add66644-a176-4fc1-9ba7-d4f9f50adc31",
"client-request-id": "add66644-a176-4fc1-9ba7-d4f9f50adc31"
}
}
}

New-MgSiteListItem_CreateExpanded1: Field 'title' is not recognized
DEBUG: [CmdletEndProcessing]: - New-MgSiteListItem end processing.

@desmay
Copy link
Author

desmay commented Apr 1, 2022

PS C:\Users\desmay> $hash

Name Value


Title Something

PS C:\Users\desmay> $PSVersionTable

Name Value


PSVersion 7.2.2
PSEdition Core
GitCommitId 7.2.2
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS C:\Users\desmay> get-module

ModuleType Version PreRelease Name ExportedCommands


Script 1.9.3 Microsoft.Graph.Authentication {Add-MgEnvironment, Connect-MgGraph, Disconnect-M…
Script 1.9.3 Microsoft.Graph.Sites {Add-MgSiteContentTypeBaseTypeCopy, Add-MgSiteCon…
Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-It…
Manifest 7.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString…
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Ob…
Manifest 7.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSSP, Disconnect-…
Script 2.1.0 PSReadLine

@rulincapo
Copy link

I am having same issue

@Attila-FIN
Copy link

I'm facing the same issue.
If I add a column TestColumn01 (capital "T") the command fails with:
"New-MgSiteListItem : Field 'testColumn01' is not recognized"

If I add a column testColumn01 (lowercase "t") the command works!

So the PowerShell module turns the field name to start with lowercase.
This must be corrected in New-MgSiteListItem!

@NamedJason
Copy link

NamedJason commented May 4, 2022

I've noticed this same issue; the New-MgSiteListItem cmdlet converts the names from the -fields hashtable to lowercase. The "Title" field in a SharePoint List always has an uppercase "T" though, so there is currently no way to populate the Title column (even if you delete all of your other columns and recreate them with only lowercase letters).

Edit: In case anyone's interested, it looks like it only converts the case of the first letter of the field. So "VMDetails" turns into "vMDetails". The issue with "Title" is still a show-stopper though, as I don't believe that we can rename that field.

@JeremyTBradshaw
Copy link

@NamedJason I noticed the same too about the lower-casing of the first letter. The error seems to come back too always for the alphabetically first field that was given. I had intent on upgrading some scripts that I've created for clients that uses MSGraphPSEssentials, as I want to switch them over to the official module. I'm trying with v1.9.6, so it seems like this issue is creeping through all the updates since v1.9.3. Darn.

@NamedJason
Copy link

@JeremyTBradshaw Thanks for the advice. I've found a workaround, if you're interested. You can use create a custom object with a property called "fields" that contains another custom object that has the internal field names of the list that you want to add an item to (basically, setting up for the JSON file in the example on https://docs.microsoft.com/en-us/graph/api/listitem-create?view=graph-rest-1.0&tabs=http). Then use invoke-mggraphrequest -uri "v1.0/sites/{site-id}/lists/{list-id}/items" -method POST -body ($listObj | convertto-json)

@JeremyTBradshaw
Copy link

@peombwa Sorry to call you directly. Just wondering if you could please confirm whether this issue right here is the best place for this issue to be reported, in order to get noticed and get fixed. Is there anywhere else we could/should report this issue to make it an official priority? Thanks in advance.

@peombwa
Copy link
Member

peombwa commented May 24, 2022

@JeremyTBradshaw, sorry for the delayed response.

This looks like a service issue since other APIs support case-insensitive JSON request bodies. Please open a question for the workload owners at https://developer.microsoft.com/graph/support for them to investigate this. We will also follow up with the workload internally.

I'll keep the issue open for us to see if we can mitigate this in the SDK by not serializing the JSON body in camelCase.

As a workaround, please use the suggestion made in #1185 (comment).

@JeremyTBradshaw
Copy link

JeremyTBradshaw commented May 25, 2022

Hi @peombwa , I opted to open an MS Support case while I have the opportunity to. It's through a Premier Support client's contract, where I'm working on several MS Graph reliant PowerShell scripts. Thinking that will be better for locking in some eyes to look into a fix. I'll wait to hear back if you think I should still / also ask the question at https://development.microsoft.com/graph/support, or if that would be unnecessary now with the support case.

Thanks again.

Update: MS Support case ended because the issue is limited to the PowerShell SDK which is not supported by MS Support. Based on this, I'm going to do as you said in the first place and will ask the question over at the site you linked.

Final update: Question asked - https://docs.microsoft.com/en-us/answers/questions/864180/problem-with-new-mgsitelistitem39s-fields-property.html

@JeremyTBradshaw
Copy link

@peombwa I've done as requested, asked the question, and then as directed from there, posted an idea. Here's hoping, and thanks.

@Mike-Crowley
Copy link

It looks like @JeremyTBradshaw is getting the hot-potato treatment on his various posts/tickets - can someone here confirm this is being worked on? I really want to love these cmdlets, but they don't make it easy.

The workaround works for me (thanks!), though it took me a while to realize 'fields' needed to be lowercase in the body too.
e.g.

$SiteId = 'c7cd1b6c-5e34-4a82-8d98-d44f81e0fd06'
$ListId = 'My%20List'
$Body = @{
    fields = @{
        column1 = "value123"
    }
}

Invoke-MgGraphRequest -Method POST -Uri "/v1.0/sites/$SiteId/lists/$ListId/items" -body ($body | ConvertTo-Json) 

@peombwa
Copy link
Member

peombwa commented Jun 2, 2022

@JeremyTBradshaw, @Mike-Crowley, sorry for the back and forth on this.

After consulting with the workload owner, the solution is for us to make the property names case insensitive as the API is case sensitive, and field names can be of any case. This means that we will serialize fields as-is.

We are working on having the fix available as part of the next SDK release. In the meantime, we recommend you use the workaround suggested above.

@JeremyTBradshaw
Copy link

Thanks for the update @peombwa . Also apologies for having put you in the hot seat. I took advantage of having seen you in another issue recently (retry handler stuff) and then noticing you were in here too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants