cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MattDendle1
New Member

Custom API webhook trigger - Delete calls not being made

Hello All -

 

I followed the guide here, and got triggers working via webhooks - apart from the webhook delete calls. What exact criteria need to be met for delete to work? I have defined the delete call in the swagger doc, and have made sure to return a Location header in the 201 create request - and that request matches the pattern of the delete call I've defined. However, the delete call is not being made correctly. Can anyone help?

Cheers,
Matt

14 REPLIES 14
MattDendle
Advocate I
Advocate I

I'm having the same issue 😄

v-monli-msft
Community Support
Community Support

Hi @MattDendle1,

 

Would you please share your OpenAPI here so that we could check if there is anything wrong?

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @v-monli-msft!

 

Thanks for your reply.

 

Here is a link to the swagger document I used to create the webhooks (along with some API calls of o...

 

Again, the webhooks work fine - they get created, I return a 201 with a location header pointing at the location to be used with the delete verb. 

 

Thanks for looking,

Matt

mhueppin
New Member

Any updates on this? I have the same issue. I return 201 with the Location Header set, delete method is defined in swagger.
Does it need a specific name? or tag? Help is much appreciated.

Cheers
Marc

I was struggling with this for a while but then I read the following text again: 

 

The webhook creation response is required to specify a "Location" header, the value of which will be used to delete the webhook registration. You must define the path of the delete webhook request as an internal action.

 

I then created an internal (hidden to end users) 'action' as part of the same custom connector. The idea is that the connector cannot make a call to an endpoint (the endpoint to delete/unsubscribe from the webhook) that is not registered. Once I created a DELETE action with the right URL structure, delete calls started to happen. 

 

Hope this helps some folks.. 

MatthijsB
Regular Visitor

Hello,

 

This is still not working for me. The webhook is being subscribed without a problem, but never unsubscribes itself.

I have a delete action on my REST controller and I tested it directly with the URL I add to the header when subscribing and the Rest call works. I add the following to the subscribe action: responseMessage.Headers.Add("Location", $"{host}/api/web-hook/delete/{id}");

 

I also tried to add an internal action to my swagger file but still nothing (I also tried without the id as parameter but hardcoded to an old subsciption, still nothing):

 

"/api/web-hook/delete/{id}": {
    "delete": {
        "responses": {
            "200": {
                "description": "OK"
            }
        },
        "summary": "Delete WebHook",
        "description": "Delete the WebHook",
        "operationId": "DeleteWebHook",
        "x-ms-visibility": "internal",
        "parameters": [
            {
                "name": "id",
                "in": "path",
                "required": true,
                "type": "string",
                "x-ms-visibility": "important",
                "x-ms-url-encoding": "single",
                "x-ms-summary": "ID",
                "description": "Specify the ID of the WebHook"
            }
        ]
    }
}

 

EDIT:

I changed it so that the ID is also hardcoded an not needed in the delete call (removed it from the response header and swagger) and I made the delete call on the REST API open for everyone and still nothing. Added logging on the first line of the method and the method doesn't even get called.

 

Thanks in advanced!

Matthijs

Hi folks,

It looks like there is one missing requirements for webhook unsubscribe operations which must be authorized as other operation in a connector. Besides having DELETE operation in the connector swagger, Location header value must start with the registered backend service Url. So, if you have delete operation template in swagger:

"/api/web-hook/delete/{id}" {"delete": {...}}

and your connector's host is 'https://myhost.com' and your Base Url is '/restapi/v2', Location header must have the following value: 'https://myhost.com/restapi/v2/api/web-hook/delete/<some id>'

Best regards,

Dmitry

Hello Dmity,

 

My location header value is exactly the same as my swagger delete operation URL, so this is not the problem.

 

location header: https://myhost.azurewebsites.net/api/web-hook/delete/42 

 

swagger host: myhost.azurewebsites.net

swagger basePath: /

swagger scheme: https

swagger path: /api/web-hook/delete/{id}

 

All the best,

Matthijs

Hi MatthijsB,

I think I found logs related to your connector and it looks like there is no Location header in a create webhook response.

One such subscription request that was sent from the connector (2020-12-09): POST https://<yourhost>.azurewebsites.net/api/web-hook/create/DocumentPropertiesUpdated. The response was successful, but there was no Location header based on logs.

I can also see few DELETE request, perhaps, it was a testing with direct action calls (webhookId=20). All of them failed with 415 status code, it looks like there is some payload passed along with those requests and Content-Type=text/plain.

 

Best regards,

Dmitry

Hello Dmitry,

 

Yes I tried a few delete webhooks via the test section. All my deletes have a 415 error code in the test section of a custom connector. Even my delete document, while the flow action for this works perfectly (and is also already certified). as you can see in the provided delete action in the swagger I don't have any body parameters. I do have consumes and produces "application/json" on top level of my swagger file.

 

My create webhook response does give a Location header as far as I can see:

{
    "version": "1.1",
    "content": null,
    "statusCode": 200,
    "reasonPhrase": "OK",
    "headers": [
        {
            "key": "Location",
            "value": [
                "https://<myhost>.azurewebsites.net/api/web-hook/delete/45"
            ]
        }
    ],
    "trailingHeaders": [],
    "requestMessage": null,
    "isSuccessStatusCode": true
}

 

All the best,

Matthijs

MatthijsB
Regular Visitor

Hello,

 

I found my issue. I upgraded my project from .NET framework to .NET Core. However the create webhook method was still returning a HttpResponseMessage which is no longer supported as a response type in a Controller in the .NET Core WebApi. So my whole response (including my location header) was begin returned in the body. I changed this to IActionResult and now it is working correctly.

 

So indeed it works by having the Location header in the create webhook response and the path of the location header as an internal delete action.

 

All the best,

Matthijs

Just to be sure. Does this mean that the owner of the API of the webhook should add a location header to the API? I'm not the owner, so I will need to ask for it then.

@JOAS_Niels  Yes.

https://docs.microsoft.com/en-us/connectors/custom-connectors/create-webhook-trigger

 Important

In order for Logic Apps or Power Automate to delete a webhook, the API must include a Location HTTP header in the 201 response at the time the webhook is created. The Location header should contain the path to the webhook that is used with the HTTP DELETE. For example, the Location included with GitHub's response follows this format: https://api.github.com/repos/<user name>/<repo name>/hooks/<hook ID>.

JOAS_Niels
Helper I
Helper I

Thanks @murshed ! I will need to submit a feature request then, that's a pity.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Microsoft Ignite 768x460.png

Find your focus

Explore the latest tools,training sessions,technical expertise, networking and more.

Top Solution Authors
Top Kudoed Authors
Users online (2,033)