Cli-microsoft365: Bug report: Adding File to SharePoint fails with status code 400, file uploads

Created on 6 Nov 2020  ยท  13Comments  ยท  Source: pnp/cli-microsoft365

Description

Receive a 400 status code error when uploading a file to SharePoint Online using m365

Steps to reproduce

Using Version 3.2.0
I am logged into m365 as myself who is a Site Collection Administrator on the site.

Using Powershell with the following command.

m365 spo file add --webUrl "https://[tenant].sharepoint.com/sites/Demo" --folder 'Shared Documents' --path 'c:\temp\filetoupload.csv'

I always get a response

node.exe : Error: Request failed with status code 400
At C:\Program Files\nodejs\m365.ps1:12 char:3
+   & "$basedir/node$exe"  "$basedir/node_modules/@pnp/cli-microsoft365 ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error: Request ...status code 400:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

The file does appear on the site.

If I use my own Azure AD Identity with certificate, which has the following permissions (incase I have them wrong):

Microsoft Graph:

  • Group.Read.All
  • Sites.Manage.All
    SharePoint:
  • Sites.FullControl.All

I also get 400 exception.

I have tried this in PowerShell, PowerShell Core and Bash and get the same response each time.

Expected result

No error message.

Actual result

node.exe : Error: Request failed with status code 400
At C:\Program Files\nodejs\m365.ps1:12 char:3
+   & "$basedir/node$exe"  "$basedir/node_modules/@pnp/cli-microsoft365 ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error: Request ...status code 400:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

m365sharepointfiles
m365bash ong
m365powershell
m365pscore

Environment

M365 CLI v 3.2.0
Windows Bash
PowerShell
PowerShell Core.

bug

Most helpful comment

Found the issue, seems to be an issue in the mapUnknownOptionsAsFieldValue method. This passes all options to map them as field values. There is a list to exclude fields, but this list is not complete, as it does not contain all the flags:

[
  { FieldName: '_', FieldValue: 'spo,file,add' },
  {
    FieldName: 'u',
    FieldValue: 'https://tenant.sharepoint.com/sites/mainsite'
  },
  { FieldName: 'f', FieldValue: 'Shared Documents' },
  {
    FieldName: 'p',
    FieldValue: '/assets/sample1.png'
  }
]

All 13 comments

Thanks for reporting @pmatthews05 and sorry for the trouble. We'll have a look if we can repro it and will take it from there ๐Ÿ‘

The ValidateUpdateListItem API returns "Column '_' does not exist. Will investigate it a bit more, as I currently require this as well for my solution.

Found the issue, seems to be an issue in the mapUnknownOptionsAsFieldValue method. This passes all options to map them as field values. There is a list to exclude fields, but this list is not complete, as it does not contain all the flags:

[
  { FieldName: '_', FieldValue: 'spo,file,add' },
  {
    FieldName: 'u',
    FieldValue: 'https://tenant.sharepoint.com/sites/mainsite'
  },
  { FieldName: 'f', FieldValue: 'Shared Documents' },
  {
    FieldName: 'p',
    FieldValue: '/assets/sample1.png'
  }
]

Our bad and good catch @estruyf.

The ValidateUpdateListItem API returns "Column '_' does not exist. Will investigate it a bit more, as I currently require this as well for my solution.

@arjunumenon did you not fix an issue like this recently on another command?

I think it was by product related to us removing the dependency on Vorpal.

/cc @waldekmastykarz

We have just released a fix for this in the latest preview version. Would you mind checking if all is working as expected @pmatthews05?

@waldekmastykarz thank you for this. I will confirm this by Monday at the latest. Not near a PC this weekend.

Excellent! Thank you once again for reporting and please, don't hesitate to reach out if there is anything out of the ordinary. Enjoy your weekend!

The ValidateUpdateListItem API returns "Column '_' does not exist. Will investigate it a bit more, as I currently require this as well for my solution.

@arjunumenon did you not fix an issue like this recently on another command?

I think it was by product related to us removing the dependency on Vorpal.

/cc @waldekmastykarz

Hey @garrytrinder - Guess I am late for the party. Seems like @waldekmastykarz has already implemented the fix. Guess I should be more fast.. ๐Ÿƒโ€โ™‚๏ธ.

You are right Garry. Issue #1903 talks about similar issue. We have to give the exception for the fields in the method which will fix the issue. Now since Waldek has alrady given the fox globally, we may not have to do that from the command scope I guess.

Thank you the reply @arjunumenon I was just sanity checking that we had seen this issue before ๐Ÿ˜Š

It was actually @estruyf who fixed it, I just happened to be the messenger. Elio fixed only this one command, not everything, so it could theoretically happen that we'll see it in other places as well.

Hi @waldekmastykarz and @estruyf,
I can confirm this is now fixed in the v3.3.0-beta.a89af63 this is working correctly. ๐Ÿ‘๐ŸŽ‰

I've tested with a service principal, added the root folder of a library, and a folder 3 levels deep. With and without the title property filled in.

I'm happy that this is working correctly.

Thank you.

When can I expect v3.3.0 to be available?

Hey @pmatthews05 ๐Ÿ‘‹๐Ÿป

We release a new stable version of the CLI at the end of every month, so expect the 3.3.0 release to be around 29th November.

Was this page helpful?
0 / 5 - 0 ratings