Skip to main content
Community site session details

Community site session details

Session Id : TGCvRox2JTAJDERXbGk8aM
Power Automate - Connector Development
Unanswered

Unable to handle delete action invoked by webhook trigger when updated for custom connector.

Like (0) ShareShare
ReportReport
Posted on 16 Jan 2024 10:26:38 by 6
We are in the middle of developing a custom connector, with some trigger and actions.
 
As per mentioned documentation we have created the trigger, and the webhook trigger subscribes with our service as expected. (Create webhook trigger).
 
The issue comes when we update any params on the webhook trigger in a flow. It's supposed to first create a new subscription in our service with call back endpoint, and then make another call using the delete action/api to delete the old registered webhook.

 

 
{
 "statusCode": 401,
 "headers": {
 "Connection": "keep-alive",
 "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
 "Date": "Mon, 15 Jan 2024 14:54:23 GMT",
 "Server": "nginx",
 "WWW-Authenticate": "Bearer",
 "Content-Length": "0"
 }
}
But here we get the error unauthorized error while saving in flow checker. Since we can see in our service that new webhook has been registered, the issue must be with delete action being invoked by webhook trigger upon updation as mentioned here (delete webhook).
 
As we are also using policy template (Set host url) on trigger to basically allow anyone using our connector to different environments (As per our use case we can have different environment hosted on different hostnames). We are taking host name from trigger parameter to register webhook as per user input.
 
But I don't think the delete Api call invocated by trigger for updation is being sent to the same host name where the webhook is created (The one overridden by set host URL policy template for trigger).
 
I think the delete action takes the host value that is provided in the general section of custom connector. Means its sharing the same credentials as the webhook trigger but not making calls to the same host.
 
Policy template details:
 
Template: Set Host Url
Url Template = https://@headers('new_url')/
 
Swagger param for webhook trigger
 
parameters": [
{
"name": "new_url",
"in": "header",
"type": "string",
"required": true,
"description": "Url for the Host environment",
"x-ms-summary": "Host Name"
},
{
other params here for webhook
}
]
What we've tried so far:
1. Applied Policy template on delete action as well (Url Template = https://abc.app.example.com/) Hardcoded the value(for testing, this also needs to be same as the one provided in webhook trigger parameter). Doesn't seem to work, as we get the same unauthorized error.
2. Also tried to get control of delete action using Custom code using c# script to change the hosturl to hardcoded value (again for testing only), but it seems this code also doesn't come into picture when trigger invokes delete action. Because when I test the c# script with delete or other action in flow etc , it runs fine and sets the host url to hardcoded value.
 
C# custom code on delete action as below.
 
public class Script : ScriptBase
{
 
 public override async Task<HttpResponseMessage> ExecuteAsync()
 {

var originalRequest = this.Context.Request;
var originalRequestBody = await originalRequest.Content.ReadAsStringAsync();


var originalRequestUrl = originalRequest.RequestUri;
var newRequestUrl = new UriBuilder(originalRequestUrl)
{
Scheme = "https",
Host = "abc.app.example.com"
}.Uri;


var mainRequest = new HttpRequestMessage(originalRequest.Method, newRequestUrl);
mainRequest.Content = new StringContent(originalRequestBody, Encoding.UTF8, "application/json");

foreach (var header in originalRequest.Headers)
{
mainRequest.Headers.TryAddWithoutValidation(header.Key, header.Value);
}


var response = await this.Context.SendAsync(mainRequest, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
return response;
 }
 }
 Our webhook updation and subsequent deletion of registered webhooks works fine when there is no policy template in picture(the Host value from general section in custom connector creation is used everywhere).
 
Since Setting host url using policy template breaks the webhook updation ,deletion behavior i.e handled by power automate (Important use case for us), Is there a way to configure the delete action invoked by trigger when user updates trigger via custom code, policy header, or other way.
 
As we couldn't find any information/ Documentation explaining the behavior. Can someone please shed some light on this.
 
P.S: We are also planning to use custom code to dynamically set authorization header for actions and and trigger (It will make calls to our authentication service and fetch auth token required, which will be added to header). In this case as well, we are facing the same error.
 
 
thanks in advance.
Categories:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2

Featured topics