pnp / cli-microsoft365

Manage Microsoft 365 and SharePoint Framework projects on any platform
https://aka.ms/cli-m365
MIT License
920 stars 326 forks source link

Bug report: Does Not Support HTTP DELETE Error on spo eventreceiver remove #4033

Closed knaopel closed 1 year ago

knaopel commented 1 year ago

Description

When attempting to remove an EventReceiver, an error is thrown that SP.EventReceiverDefinitionCollection does not support HTTP DELETE method.

Steps to reproduce

Expected results

Expect Event Receiver to be removed

Actual results

Receive Error: The type SP.EventReceiverDefinitionCollection does not support HTTP DELETE method. image

Diagnostics

Request: { "url": "https://contoso.sharepoint.com/sites/dev/_api/web/lists(guid'fa8e7ec4-4652-4aa8-b480-9f78e7bc5bc0')/eventreceivers?$filter=receiverid eq (guid'dcac6a72-cfe3-4a0b-8f34-b36d6d9dc1a9')", "method": "delete", "headers": { "common": { "Accept": "application/json, text/plain, /" }, "delete": {}, "get": {}, "head": {}, "post": { "Content-Type": "application/x-www-form-urlencoded" }, "put": { "Content-Type": "application/x-www-form-urlencoded" }, "patch": { "Content-Type": "application/x-www-form-urlencoded" }, "user-agent": "NONISV|SharePointPnP|CLIMicrosoft365/5.9.0", "accept-encoding": "gzip, deflate", "accept": "application/json;odata=nometadata", "authorization": "Bearer " }, "responseType": "json", "decompress": true } Request error: { "url": "https://contoso.sharepoint.com/sites/dev/_api/web/lists(guid'fa8e7ec4-4652-4aa8-b480-9f78e7bc5bc0')/eventreceivers?$filter=receiverid eq (guid'dcac6a72-cfe3-4a0b-8f34-b36d6d9dc1a9')", "status": 400, "statusText": "Bad Request", "headers": { "cache-control": "private, max-age=0", "transfer-encoding": "chunked", "content-type": "application/json;odata=nometadata;streaming=true;charset=utf-8", "expires": "Wed, 26 Oct 2022 19:40:40 GMT", "last-modified": "Thu, 10 Nov 2022 20:40:40 GMT", "vary": "Origin", "p3p": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"", "x-networkstatistics": "0,525568,0,63,5679719,0,525568", "x-sharepointhealthscore": "2", "x-sp-serverstate": "ReadOnly=0", "dataserviceversion": "3.0", "spclientservicerequestduration": "14", "x-aspnet-version": "4.0.30319", "x-databoundary": "None", "x-1dscollectorurl": "https://mobile.events.data.microsoft.com/OneCollector/1.0/", "x-ariacollectorurl": "https://browser.pipe.aria.microsoft.com/Collector/3.0/", "sprequestguid": "2c5777a0-20d8-2000-db15-4002a7dc2c7a", "request-id": "2c5777a0-20d8-2000-db15-4002a7dc2c7a", "ms-cv": "oHdXLNggACDbFUACp9wseg.0", "strict-transport-security": "max-age=31536000", "x-frame-options": "SAMEORIGIN", "content-security-policy": "frame-ancestors 'self' teams.microsoft.com .teams.microsoft.com .skype.com .teams.microsoft.us local.teams.office.com .powerapps.com .yammer.com .officeapps.live.com .office.com .stream.azure-test.net .microsoftstream.com .dynamics.com *.microsoft.com securebroker.sharepointonline.com;", "x-powered-by": "ASP.NET", "microsoftsharepointteamservices": "16.0.0.23019", "x-content-type-options": "nosniff", "x-ms-invokeapp": "1; RequireReadOnly", "x-cache": "CONFIG_NOCACHE", "x-msedge-ref": "Ref A: 8EF09F5DE77E4ED99556FF57B87AFA69 Ref B: DTT311000101011 Ref C: 2022-11-10T20:40:40Z", "date": "Thu, 10 Nov 2022 20:40:39 GMT", "connection": "close" }, "error": { "odata.error": { "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException", "message": { "lang": "en-US", "value": "The type SP.EventReceiverDefinitionCollection does not support HTTP DELETE method." } } } }

CLI for Microsoft 365 version

v5.9.0

nodejs version

v16.18.0

Operating system (environment)

Windows

Shell

PowerShell

cli doctor

{ "os": { "platform": "win32", "version": "Windows 10 Pro", "release": "10.0.22621" }, "cliVersion": "5.9.0", "nodeVersion": "v16.18.0", "cliAadAppId": "31359c7f-bd7e-475c-86db-fdb8c937548e", "cliAadAppTenant": "common", "authMode": "DeviceCode", "cliEnvironment": "", "cliConfig": {}, "roles": [], "scopes": [ "AllSites.FullControl", "AppCatalog.ReadWrite.All", "ChannelMember.ReadWrite.All", "ChannelMessage.Send", "ChannelSettings.ReadWrite.All", "Directory.AccessAsUser.All", "Directory.ReadWrite.All", "Group.ReadWrite.All", "IdentityProvider.ReadWrite.All", "Mail.ReadWrite", "Mail.Send", "Policy.Read.All", "Reports.Read.All", "Tasks.ReadWrite", "Team.Create", "TeamMember.ReadWrite.All", "TeamsApp.ReadWrite.All", "TeamsAppInstallation.ReadWriteForUser", "TeamSettings.ReadWrite.All", "TeamsTab.ReadWrite.All", "TermStore.ReadWrite.All", "User.Invite.All", "User.ReadWrite.All", "profile", "openid", "email", "AllSites.FullControl", "AppCatalog.ReadWrite.All", "ChannelMember.ReadWrite.All", "ChannelMessage.Send", "ChannelSettings.ReadWrite.All", "Directory.AccessAsUser.All", "Directory.ReadWrite.All", "Group.ReadWrite.All", "IdentityProvider.ReadWrite.All", "Mail.ReadWrite", "Mail.Send", "Policy.Read.All", "Reports.Read.All", "Tasks.ReadWrite", "Team.Create", "TeamMember.ReadWrite.All", "TeamsApp.ReadWrite.All", "TeamsAppInstallation.ReadWriteForUser", "TeamSettings.ReadWrite.All", "TeamsTab.ReadWrite.All", "TermStore.ReadWrite.All", "User.Invite.All", "User.ReadWrite.All" ] }

Additional Info

No response

nicodecleyre commented 1 year ago

Thank you for reporting this! It May be a good idea to sanitise your output. Can we ask you to remove the access token & the tenant name in the SharePoint url in your output?

milanholemans commented 1 year ago

Hi @knaopel

Thank you for making this report. We'll have a look at it!

milanholemans commented 1 year ago

Hi @knaopel I made a PR to fix the issue. While we wait for it to be approved, you can help yourself with following command to remove the event receiver:

m365 request --url https://contoso.sharepoint.com/sites/dev/_api/web/lists('fa8e7ec4-4652-4aa8-b480-9f78e7bc5bc0')/eventreceivers('dcac6a72-cfe3-4a0b-8f34-b36d6d9dc1a9') --method delete

Thanks again for bringing this to the surface!

knaopel commented 1 year ago

Thanks for the tip @milanholemans ! However when I issue the command as written I get a 403 Bad request error image

milanholemans commented 1 year ago

Hi @knaopel weird!

Tried it myself, created an event receiver via PnP.PowerShell, and removed it with the same CLI command I provided you.

afbeelding

I can confirm the event receiver got deleted as expected.

The only thing I can think of is the fact that event receivers are quite annoying to remove. You have to remove them with the same app id as the one who registered it. (I see that this remark seems to be missing in our docs). However, when I google this behavior, I see the following.

When registering a Remote Event Receiver from an App for SharePoint, SharePoint automatically adds the App ID to the Event Receiver’s registration information. One of the consequences of this is the fact, that you will be able to remove that particular Event Receiver only by using the same app that registered it! If you try to remove an Event Receiver that has been registered by an app with a different ID you will get a Server Unauthorized Access Exception.

But it seems like you are getting a different error here. Do you know with which context you created the event receiver?

milanholemans commented 1 year ago

@knaopel in the meantime, my PR got merged so the command is updated in the CLI beta release (npm i -g @pnp/cli-microsoft365@next).

You might try that one, however it will probably give the same result for you.