Jeremy Bradshaw
Jeremy Bradshaw

Reputation: 119

400 Bad Request with MS Graph when adding list items

For the life of me I can't successfully add SharePoint list items. I have in the past, now I'm stumped, using either Invoke-WebRequest or Invoke-RestMethod. I am able to update (PATCH) without issue, and can do all sorts of GET operations against the same sites, lists, items, etc.

Here's a fiddler capture of my actual HTTP POST request (Guid's fudged):

POST https://graph.microsoft.com/v1.0/sites/2df3a5af-979d-46d6-b24d-14e4e4b58aa9/lists/2252b849-53f9-4816-bc0b-d9183357c702/items HTTP/1.1
Content-Type: application/json
Authorization: Bearer eyJ0f...
User-Agent: MSGraphPSEssentials/0.4.0
Host: graph.microsoft.com
Content-Length: 537

{
    "Fields":  {
                   "AccountStatus":  "Enabled",
                   "DisplayName":  "Fictional User 1",
                   "UserId":  "67853e89-65a9-431d-a3b1-1d60ab74dc1f",
                   "ADObjectGuid":  "56752e89-65a9-431d-a3b1-1d61ab78dc1f",
                   "AccountCreated":  "2019-03-12",
                   "AADObjectId":  "8df5db8d-1d7a-4b35-b498-138eef2946fa",
                   "AccountType":  "AD-Synced",
                   "ADLastLogonDate":  "2020-08-25"
               }
}

For each of the fields/columns shown, the content type on the SPO list is either "single line of text" or "date and time", and in either case, no data is required. There are no other columns on the list that are required (purposely while I troubleshoot this).

Can anyone spot anything obvious that would cause me to receive 400 Bad Request and the only additional info provided is "Invalid Request"

Here's a fiddler capture of an example response:

HTTP/1.1 400 Bad Request
Date: Thu, 29 Apr 2021 14:26:08 GMT
Content-Type: application/json
Cache-Control: no-cache
Transfer-Encoding: chunked
Strict-Transport-Security: max-age=31536000
request-id: 87190763-4bfe-4a88-a69e-154fd60aad81
client-request-id: 87190763-4bfe-4a88-a69e-154fd60aad81
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"East US","Slice":"E","Ring":"5","ScaleUnit":"004","RoleInstance":"BL02EPF000035AB"}}

da
{"error":{"code":"invalidRequest","message":"Invalid request","innerError":{"date":"2021-04-29T14:26:08","request-id":"87190763-4bfe-4a88-a69e-154fd60aad81","client-request-id":"87190763-4bfe-4a88-a69e-154fd60aad81"}}}
0

Finally, here are the columns as returned by successful MS Graph request to /sites/<ID>/lists/<ID>?Expand=Columns:

>$columns.columns |select Name, DisplayName, ReadOnly, Required

name                      displayName             readOnly required
----                      -----------             -------- --------
ManagerDisplayName        ManagerDisplayName         False    False
ManagerEmail              ManagerEmail               False    False
Ignore                    Ignore                     False    False
UserId                    UserId                     False    False
Title                     Title                      False    False
ComplianceAssetId         Compliance Asset Id         True    False
IgnoreReason              IgnoreReason               False    False
ADObjectGuid              ADObjectGuid               False    False
AADObjectId               AADObjectId                False    False
ADLastLogonDate           ADLastLogonDate            False    False
AADLastSignIn             AADLastSignIn              False    False
DisabledDate              DisabledDate               False    False
ReEnabledDate             ReEnabledDate              False    False
JobTitle                  JobTitle                   False    False
Status                    Status                     False    False
ResolvedReason            ResolvedReason             False    False
NewAADLastSignIn          NewAADLastSignIn           False    False
AssignedLicenses          AssignedLicenses           False    False
AADCreationType           AADCreationType            False    False
AccountCreated            AccountCreated             False    False
DisplayName               DisplayName                False    False
Email                     Email                      False    False
AccountType               AccountType                False    False
NewADLastLogonDate        NewADLastLogonDate         False    False
ID                        ID                          True    False
ContentType               Content Type               False    False
Modified                  Modified                    True    False
Created                   Created                     True    False
Author                    Created By                  True    False
Editor                    Modified By                 True    False
_UIVersionString          Version                     True    False
Attachments               Attachments                False    False
Edit                      Edit                        True    False
LinkTitleNoMenu           Title                       True    False
LinkTitle                 Title                       True    False
DocIcon                   Type                        True    False
ItemChildCount            Item Child Count            True    False
FolderChildCount          Folder Child Count          True    False
_ComplianceFlags          Label setting               True    False
_ComplianceTag            Retention label             True    False
_ComplianceTagWrittenTime Retention label Applied     True    False
_ComplianceTagUserId      Label applied by            True    False
_IsRecord                 Item is a Record            True    False
AppAuthor                 App Created By              True    False
AppEditor                 App Modified By             True    False

My problem is 100% only with adding new items. I wish there was more helpful info in the returned error response. Note, I'm getting the same behavior if I try to do this through the $batch endpoint. Here's the error info available that way:

>$test.responses.body.Error

code           message         innerError
----           -------         ----------
invalidRequest Invalid request @{date=2021-04-29T14:41:34; request-id=cdf96c25-41e1-437b-9698-64389a2dc36b; client-request-id=cdf96c25-41e1-437b-9698-64389a2dc36b}

...again just 'Invalid Request' :(.

Upvotes: 0

Views: 1440

Answers (1)

Jeremy Bradshaw
Jeremy Bradshaw

Reputation: 119

Shamefully this problem was simply the capital "F" in "Fields" in my body. It is case sensitive (evidently). "fields" solved it. I was going to delete the question, but in case it might help someone I'll leave it.

Upvotes: 2

Related Questions