cli-microsoft365 icon indicating copy to clipboard operation
cli-microsoft365 copied to clipboard

Bug Report: m365 spo file rename is non-functional due to inconsistent parameters; m365 request has usability issues.

Open msouga opened this issue 1 year ago • 3 comments

Priority

(Medium) I'm annoyed but I'll live

Description

The m365 spo file rename command appears to be unusable in its current state. All logical attempts to use it result in "Invalid option" errors, making it impossible to rename a file via this command.

Additionally, the m365 request command shows some usability issues, particularly with case-sensitivity in the --method parameter and potential parsing problems with the --body and --headers parameters, making it an unreliable alternative for direct API calls.

Steps to reproduce

  1. Identify any file in a SharePoint document library.
  2. Attempt to rename it using any of the following command variations.

Variables used in examples:

  • --webUrl: https://[tenant].sharepoint.com/sites/[site]
  • --sourceUrl: /sites/[site]/[library]/[file].docx
  • --targetUrl: /sites/[site]/[library]/[new-name].docx
  • --fileId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  • --newName: [new-name].docx

Attempt 1: Using --sourceUrl and --newName

m365 spo file rename --webUrl "..." --sourceUrl "..." --newName "..." FAILS with: Error: Invalid option: 'newName'

Attempt 2: Using --sourceUrl and --targetUrl

m365 spo file rename --webUrl "..." --sourceUrl "..." --targetUrl "..." FAILS with: Error: Invalid option: 'targetUrl'

Attempt 3: Using --fileId and --newName

m365 spo file rename --webUrl "..." --fileId "..." --newName "..." FAILS with: Error: Invalid option: 'fileId'

Expected results

One of the command combinations above should successfully rename the file as per the provided parameters.

Actual results

Every attempt fails with an Error: Invalid option: '[parameter]' message, indicating that the command does not recognize its own parameters as documented or expected.

Diagnostics

When running the command with the --debug flag, it fails immediately with the same "Invalid option" error and produces no additional debug output. This indicates the failure occurs during the initial command-line argument parsing, before any operational logic is executed.

CLI for Microsoft 365 version

v10.9.0

nodejs version

v20.19.3

Operating system (environment)

macOS

Shell

zsh

cli doctor

authMode : browser cliConfig : {"autoOpenLinksInBrowser":true,"copyDeviceCodeToClipboard":true,"output":"text","printErrorsAsPlainText":true,"prompt":true,"showHelpOnFailure":true,"helpMode":"full","authType":"browser","clientId":"08f28f0f-4f84-4bbb-a30b-b5aaef148dc4","tenantId":"e41cc5ba-be22-4d17-a617-d9414fbde6e5","clientSecret":"","clientCertificateFile":"","clientCertificateBase64Encoded":""} cliEntraAppId : 08f28f0f-4f84-4bbb-a30b-b5aaef148dc4 cliEntraAppTenant: single cliEnvironment : cliVersion : 10.9.0 nodeVersion : v20.19.3 os : {"platform":"darwin","version":"Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:25 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6020","release":"24.5.0"} roles : [] scopes : {"https://graph.microsoft.com":["AllSites.FullControl","AppCatalog.ReadWrite.All","AuditLog.Read.All","Bookings.Read.All","Calendars.Read","ChannelMember.ReadWrite.All","ChannelMessage.Read.All","ChannelMessage.ReadWrite","ChannelMessage.Send","ChannelSettings.ReadWrite.All","Chat.ReadWrite","Community.ReadWrite.All","Directory.AccessAsUser.All","Directory.ReadWrite.All","ExternalConnection.ReadWrite.All","ExternalItem.ReadWrite.All","FileStorageContainer.Selected","Group.ReadWrite.All","IdentityProvider.ReadWrite.All","InformationProtectionPolicy.Read","Mail.Read.Shared","Mail.ReadWrite","Mail.Send","MailboxSettings.ReadWrite","Notes.ReadWrite.All","OnlineMeetingArtifact.Read.All","OnlineMeetings.ReadWrite","OnlineMeetingTranscript.Read.All","Organization.ReadWrite.All","PeopleSettings.ReadWrite.All","Place.Read.All","Policy.Read.All","Policy.Read.PermissionGrant","RecordsManagement.ReadWrite.All","Reports.Read.All","ReportSettings.ReadWrite.All","RoleAssignmentSchedule.ReadWrite.Directory","RoleEligibilitySchedule.Read.Directory","RoleManagement.Read.Directory","SecurityEvents.Read.All","ServiceHealth.Read.All","ServiceMessage.Read.All","ServiceMessageViewpoint.Write","Sites.Read.All","Tasks.ReadWrite","Team.Create","TeamMember.ReadWrite.All","TeamsAppInstallation.ReadWriteForUser","TeamSettings.ReadWrite.All","TeamsTab.ReadWrite.All","TermStore.ReadWrite.All","User.Invite.All","User.ReadWrite.All","profile","openid","email"],"00000003-0000-0ff1-ce00-000000000000":["AllSites.FullControl","AppCatalog.ReadWrite.All","AuditLog.Read.All","Bookings.Read.All","Calendars.Read","ChannelMember.ReadWrite.All","ChannelMessage.Read.All","ChannelMessage.ReadWrite","ChannelMessage.Send","ChannelSettings.ReadWrite.All","Chat.ReadWrite","Community.ReadWrite.All","Directory.AccessAsUser.All","Directory.ReadWrite.All","ExternalConnection.ReadWrite.All","ExternalItem.ReadWrite.All","FileStorageContainer.Selected","Group.ReadWrite.All","IdentityProvider.ReadWrite.All","InformationProtectionPolicy.Read","Mail.Read.Shared","Mail.ReadWrite","Mail.Send","MailboxSettings.ReadWrite","Notes.ReadWrite.All","OnlineMeetingArtifact.Read.All","OnlineMeetings.ReadWrite","OnlineMeetingTranscript.Read.All","Organization.ReadWrite.All","PeopleSettings.ReadWrite.All","Place.Read.All","Policy.Read.All","Policy.Read.PermissionGrant","RecordsManagement.ReadWrite.All","Reports.Read.All","ReportSettings.ReadWrite.All","RoleAssignmentSchedule.ReadWrite.Directory","RoleEligibilitySchedule.Read.Directory","RoleManagement.Read.Directory","SecurityEvents.Read.All","ServiceHealth.Read.All","ServiceMessage.Read.All","ServiceMessageViewpoint.Write","Sites.Read.All","Tasks.ReadWrite","Team.Create","TeamMember.ReadWrite.All","TeamsAppInstallation.ReadWriteForUser","TeamSettings.ReadWrite.All","TeamsTab.ReadWrite.All","TermStore.ReadWrite.All","User.Invite.All","User.ReadWrite.All"]}

Additional Info

This bug was discovered while using the CLI programmatically via the Gemini CLI. This is a non-interactive environment where commands are executed as isolated processes. This context highlights the need for reliable, non-interactive commands for automation scenarios.

Successful Workaround (Proof that the API works) We confirmed that the user's permissions were correct and the underlying Graph API endpoint is functional. The file was successfully renamed by generating an access token with m365 util accesstoken get and then executing a curl command directly in the user's terminal.

This proves the issue lies within the m365 CLI tool's parameter handling for this specific command, not with the user's permissions or the SharePoint API itself.

Working curl command structure:

  1. Get Token ACCESS_TOKEN=$(m365 util accesstoken get --resource https://graph.microsoft.com --new)

  2. Execute API Call Note: The correct Drive ID was required, not the List ID. DRIVE_ID=$(m365 request --url "https://graph.microsoft.com/v1.0/sites/{site-id}/drive" --query "id")

curl --location --request PATCH "https://graph.microsoft.com/v1.0/drives/$DRIVE_ID/items/{item-id}"
--header "Authorization: Bearer $ACCESS_TOKEN"
--header 'Content-Type: application/json'
--data-raw '{"name": "new-file-name.docx"}'

Additional context**

We hope this detailed report helps improve this command. A reliable spo file rename is crucial for automation scripts.

Thank you for your work on this excellent tool.

msouga avatar Jul 10 '25 17:07 msouga

Hi @msouga, I think the Gemini CLI suggested the wrong command options. If you take a look at our docs, you can see that the command expects 3 parameters:

  • webUrl
  • sourceUrl
  • targetFileName

So instead of newName or targetUrl, you should use targetFileName instead. Can you confirm that this works for you?

milanholemans avatar Jul 10 '25 22:07 milanholemans

@msouga did you try using CLI for Microsoft 365 MCP server?

Adam-it avatar Jul 14 '25 08:07 Adam-it

Closing due to lack of response

waldekmastykarz avatar Nov 15 '25 10:11 waldekmastykarz