Problem in Deleting Remote Event Receiver in Sharepoint

%3CLINGO-SUB%20id%3D%22lingo-sub-31583%22%20slang%3D%22en-US%22%3EProblem%20in%20Deleting%20Remote%20Event%20Receiver%20in%20Sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-31583%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20Remote%20event%20Receiver%20to%20a%20document%20library%20using%20Provider%20hosted%20app.Now%20i%20am%20trying%20to%20delete%20(Provider%20hosted%20app)%20the%20same%20remote%20event%20Receiver%26nbsp%3B%20but%20i%20am%20getting%20%22Microsoft.SharePoint.Client.ServerUnauthorizedAccessException%3A%20Access%20denied.%20You%20do%20not%20have%20permission%20to%20perform%20this%20action%20or%20access%20this%20resource.%22%20error.%3C%2FP%3E%3CP%3EIs%20there%20any%20other%20way%20apart%20from%20running%20powershell%20script%20to%20delete%20the%20attached%20remote%20event%20Receiver%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-74827%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20Problem%20in%20Deleting%20Remote%20Event%20Receiver%20in%20Sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-74827%22%20slang%3D%22en-US%22%3E%3CP%3EPowershell%20method%20gives%20access%20denied%20error.%20Is%20there%20any%20way%20we%20can%20deleted%20the%20event%20receiver%20without%20deleting%20the%20list%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-31750%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20Problem%20in%20Deleting%20Remote%20Event%20Receiver%20in%20Sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-31750%22%20slang%3D%22en-US%22%3E%3CP%3Eyeah%20i%20think%20now%20powershell%20is%20the%20only%20option%20.%3C%2FP%3E%3CP%3EBecause%20the%20issue%20was%20not%20with%26nbsp%3Bthe%20appid%20change%20but%20the%20farm%20id%20change%20because%20of%20which%20the%20entire%20AppId%20was%20not%20matching%20and%20hence%20giving%20access%20denied%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20replies%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-31718%22%20slang%3D%22en-US%22%3ERE%3A%20Problem%20in%20Deleting%20Remote%20Event%20Receiver%20in%20Sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-31718%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20do%20this%20first%20by%20searching%20it%20in%20the%20SharePoint%20ClientBrowser%20and%20then%20use%20a%20powershell%20script%20to%20delete%20it.%3C%2FP%3E%3CPRE%3Efunction%20Get-SPOListEventreceivers%0A%7B%0Aparam%20(%0A%20%20%5BParameter(Mandatory%3D%24true%2CPosition%3D1)%5D%0A%20%20%5Bstring%5D%24Username%2C%0A%20%20%5BParameter(Mandatory%3D%24true%2CPosition%3D2)%5D%0A%20%20%24AdminPassword%2C%0A%20%20%20%20%20%20%20%20%5BParameter(Mandatory%3D%24true%2CPosition%3D3)%5D%0A%20%20%5Bstring%5D%24Url%2C%0A%20%20%20%20%20%20%20%20%5BParameter(Mandatory%3D%24true%2CPosition%3D4)%5D%0A%20%20%5Bstring%5D%24ListTitle%2C%0A%20%20%20%20%20%20%20%20%5BParameter(Mandatory%3D%24true%2CPosition%3D5)%5D%0A%20%20%5BGUID%5D%24EventReceiverGUID%0A)%0A%0A%20%20%24ctx%3DNew-Object%20Microsoft.SharePoint.Client.ClientContext(%24Url)%0A%20%20%24ctx.Credentials%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24Username%2C%20%24AdminPassword)%0A%0Atry%0A%7B%0A%24ctx.ExecuteQuery()%0A%7D%20catch%20%5BNet.WebException%5D%20%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20Write-Host%20%24Url%20%22%20failed%20to%20connect%20to%20the%20site%22%20%24_.Exception.Message.ToString()%20-ForegroundColor%20Red%0A%7D%0A%0A%20%24ctx.Load(%24ctx.Site)%0A%0A%20%20%24lista%3D%24ctx.Web.Lists.GetByTitle(%24ListTitle)%0A%20%24ctx.Load(%24lista)%0A%20%20%24ctx.ExecuteQuery()%0A%20%24recevery%3D%24lista.EventReceivers%0A%20%24ctx.Load(%24recevery)%0A%20%24ctx.ExecuteQuery()%0A%20Write-Host%20%22Found%20%22%20%24recevery.Count%20%22%20receivers%20in%20%22%20%24lista.Title%0A%0A%24recevery.GetById(%24EventReceiverGUID).DeleteObject()%0A%0Atry%0A%7B%0A%24ctx.ExecuteQuery()%0AWrite-Host%20%22receiver%20removed%22%0A%7D%0A%0A%20catch%20%5BNet.WebException%5D%20%0A%20%20%7B%0A%20%20Write-Host%20%22Failed%20to%20delete%20the%20receiver%22%20%24_.Exception.Message.ToString()%20-ForegroundColor%20Red%0A%20%20%7D%0A%0A%7D%0A%0A%0A%23%20Paths%20to%20SDK.%20Please%20verify%20location%20on%20your%20computer.%0AAdd-Type%20-Path%20%22c%3A%5CProgram%20Files%5CCommon%20Files%5Cmicrosoft%20shared%5CWeb%20Server%20Extensions%5C15%5CISAPI%5CMicrosoft.SharePoint.Client.dll%22%20%0AAdd-Type%20-Path%20%22c%3A%5CProgram%20Files%5CCommon%20Files%5Cmicrosoft%20shared%5CWeb%20Server%20Extensions%5C15%5CISAPI%5CMicrosoft.SharePoint.Client.Runtime.dll%22%20%0A%0A%23%20Insert%20the%20credentials%20and%20the%20name%20of%20the%20admin%20site%0A%24Username%3D%22spadmin%40xxx.onmicrosoft.com%22%20%0A%24password%20%3D%20%22%24xxxx%22%20%0A%24url%20%3D%20%22https%3A%2F%2Fxxxx.sharepoint.com%2Fsites%2FS046WW16776%22%0A%24AdminPassword%3DRead-Host%20-Prompt%20%22Password%22%20-AsSecureString%0A%24Url%3D%22https%3A%2F%2Fxxx.sharepoint.com%2Fsites%2FS046WW16776%22%0A%24ListTitle%3D%22Project%20Metadata%22%0A%24EventReceiverGUID%3D%228ded46d9-6b87-4dac-9532-64d013122e92%22%0A%0AGet-SPOListEventreceivers%20-Username%20%24Username%20-AdminPassword%20%24AdminPassword%20-Url%20%24Url%20-ListTitle%20%24ListTitle%20-EventReceiverGUID%20%24EventreceiverGUID%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-31709%22%20slang%3D%22en-US%22%3ERe%3A%20Problem%20in%20Deleting%20Remote%20Event%20Receiver%20in%20Sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-31709%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20need%20to%20remove%20the%20remote%20event%20reciever%20using%20the%20same%20ClientID%20that%20created%20it.%20So%20if%20your%20provider%20hosted%20app%20with%20a%20specific%20clientid%20was%20used%20to%20create%20the%20event%20reciever%20you%20will%20get%20access%20denied%20if%20you%20try%20to%20delete%20it%20with%20powershell%20using%20your%20credentials.%20However%20i%20do%20believe%20that%20the%20pnp%20powershell%20Connect-SPOnline%20has%20some%20parameters%20to%20connect%20with%20clientid%20and%20secret.%20You%20should%20be%20able%20to%20delete%20it%20then%3CBR%20%2F%3E%3CBR%20%2F%3EI%20do%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1169309%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20Problem%20in%20Deleting%20Remote%20Event%20Receiver%20in%20Sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1169309%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F59908%22%20target%3D%22_blank%22%3E%40Prerak%20Desai%3C%2FA%3EI%20am%20facing%20the%20exact%20same%20issue..%20unable%20to%20remove%20the%20RER%20using%20PnP%20either%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1169363%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20Problem%20in%20Deleting%20Remote%20Event%20Receiver%20in%20Sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1169363%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F233354%22%20target%3D%22_blank%22%3E%40john%20john%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20john%20may%20I%20know%20if%20you%20are%20using%20sharepoint%20online%20version%20or%20on%20premise%20version%3F%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%26nbsp%3B%20RER%20can%20be%20removed%20by%20the%20app%20that%20registered%20it.%20In%20our%20scenario%20farm%20realm%20id%20got%20changed%20because%20of%20which%20even%20the%20same%20app%20was%20not%20able%20to%20delete%20the%20remote%20event%20receiver.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20order%20to%20get%20rid%20of%20the%20remote%20event%20receiver%20we%20used%20brute%20force%20.%20Instead%20of%20client%20side%20code%20we%20wrote%20server%20side%20PowerShell%20script%20to%20delete%20the%26nbsp%3B%20remote%20event%20receiver%20which%20worked%20for%20us.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1506163%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20Problem%20in%20Deleting%20Remote%20Event%20Receiver%20in%20Sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1506163%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F31897%22%20target%3D%22_blank%22%3E%40bhartisemwal1990%3C%2FA%3E%26nbsp%3BThanks%2C%20We%20were%20facing%20the%20same%20issue.%20Your%20suggestion%20helped%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hi ,

 

I have attached Remote event Receiver to a document library using Provider hosted app.Now i am trying to delete (Provider hosted app) the same remote event Receiver  but i am getting "Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: Access denied. You do not have permission to perform this action or access this resource." error.

Is there any other way apart from running powershell script to delete the attached remote event Receiver

7 Replies
Highlighted

You need to remove the remote event reciever using the same ClientID that created it. So if your provider hosted app with a specific clientid was used to create the event reciever you will get access denied if you try to delete it with powershell using your credentials. However i do believe that the pnp powershell Connect-SPOnline has some parameters to connect with clientid and secret. You should be able to delete it then

I do

Highlighted

You can do this first by searching it in the SharePoint ClientBrowser and then use a powershell script to delete it.

function Get-SPOListEventreceivers
{
param (
  [Parameter(Mandatory=$true,Position=1)]
		[string]$Username,
		[Parameter(Mandatory=$true,Position=2)]
		$AdminPassword,
        [Parameter(Mandatory=$true,Position=3)]
		[string]$Url,
        [Parameter(Mandatory=$true,Position=4)]
		[string]$ListTitle,
        [Parameter(Mandatory=$true,Position=5)]
		[GUID]$EventReceiverGUID
)

  $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)

try
{
$ctx.ExecuteQuery()
} catch [Net.WebException] 
        {
            
            Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red
}

 $ctx.Load($ctx.Site)

  $lista=$ctx.Web.Lists.GetByTitle($ListTitle)
 $ctx.Load($lista)
  $ctx.ExecuteQuery()
 $recevery=$lista.EventReceivers
 $ctx.Load($recevery)
 $ctx.ExecuteQuery()
 Write-Host "Found " $recevery.Count " receivers in " $lista.Title

$recevery.GetById($EventReceiverGUID).DeleteObject()

try
{
$ctx.ExecuteQuery()
Write-Host "receiver removed"
}

 catch [Net.WebException] 
  {
  Write-Host "Failed to delete the receiver" $_.Exception.Message.ToString() -ForegroundColor Red
  }

}


# Paths to SDK. Please verify location on your computer.
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 

# Insert the credentials and the name of the admin site
$Username="spadmin@xxx.onmicrosoft.com" 
$password = "$xxxx" 
$url = "https://xxxx.sharepoint.com/sites/S046WW16776"
$AdminPassword=Read-Host -Prompt "Password" -AsSecureString
$Url="https://xxx.sharepoint.com/sites/S046WW16776"
$ListTitle="Project Metadata"
$EventReceiverGUID="8ded46d9-6b87-4dac-9532-64d013122e92"

Get-SPOListEventreceivers -Username $Username -AdminPassword $AdminPassword -Url $Url -ListTitle $ListTitle -EventReceiverGUID $EventreceiverGUID
Highlighted

yeah i think now powershell is the only option .

Because the issue was not with the appid change but the farm id change because of which the entire AppId was not matching and hence giving access denied error.

 

Thanks for replies :)

Highlighted

Powershell method gives access denied error. Is there any way we can deleted the event receiver without deleting the list

Highlighted

@Prerak DesaiI am facing the exact same issue.. unable to remove the RER using PnP either

Highlighted

@john john 

 

Hi john may I know if you are using sharepoint online version or on premise version??

 

 

As  RER can be removed by the app that registered it. In our scenario farm realm id got changed because of which even the same app was not able to delete the remote event receiver.

 

In order to get rid of the remote event receiver we used brute force . Instead of client side code we wrote server side PowerShell script to delete the  remote event receiver which worked for us.

 

 

 

Highlighted

@bhartisemwal1990 Thanks, We were facing the same issue. Your suggestion helped