Solved

REST API call returns 406 when doing a webhook DELETE

FedeGala
Tourist
6 0 5

Hi,

I created an app that registers a few webhooks during installation using the "registerWebhooks" method from the NPM package "@shopify/koa-shopify-webhooks". The delivery method in the registration is "EventBridge" and the access token used is the first one generated during installation, which is of access mode "online".

I'm able to make GET calls to "admin/api/2021-01/webhooks.json" using the latest access token for the session, but when I try to do a DELETE on "admin/api/2021-01/webhooks/{webhookID}.json", I'm getting a 406 Not Acceptable back. 

How can I solve this?

Thank you in advance!

Accepted Solution (1)
Kevin_A
Shopify Staff
318 42 61

This is an accepted solution.

Hey @FedeGala 

It looks like the issue here is that you are sending the request as a POST instead of a DELETE. Please make sure you are sending a DELETE request. 

Kevin_A | Solutions Engineer @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 8 (8)

Kevin_A
Shopify Staff
318 42 61

Hey @FedeGala 

Can you provide us with the x-request-id response header from your delete request please?

Kevin_A | Solutions Engineer @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

FedeGala
Tourist
6 0 5

Hi Kevin,

Of course, here it is: f866c562-e1a3-4d91-a462-837a1ddc540a

Thank you for looking into this!

Kevin_A
Shopify Staff
318 42 61

This is an accepted solution.

Hey @FedeGala 

It looks like the issue here is that you are sending the request as a POST instead of a DELETE. Please make sure you are sending a DELETE request. 

Kevin_A | Solutions Engineer @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

FedeGala
Tourist
6 0 5

Hi Kevin,

 

It's always the dumb mistakes that get you. Thank you for pointing mine out! All works now.

CubiGear
Shopify Partner
31 3 7

I'm really using DELETE here and I still get 406 - Not Acceptable.  Any ideas ?

ali-n
Shopify Partner
2 0 0

same here.

X-Request-ID: 0b8d1a02-107e-41a0-908c-523512d4aa4f

ali-n
Shopify Partner
2 0 0

ok stupid mistake, I had copied the url path from the get request and it did not include "/webhooks/"

working fine now.

correct url:
 https://storeName.myshopify.com/admin/api/apiVersion/webhooks/webhookId.json

CubiGear
Shopify Partner
31 3 7

I've been able to delete but using the id.  The guid is not acceptable.  Here's how :
Since I created a webhook by code I'm getting the last one.  It's not elegant of course but deleting a webhook using the id works like a charm.  The problem is that Shopify gives a GUID in the header when a Bulk Operation webhook has finished and not the id which is what is needed.  So here I don't know how to get a webook by the guid to get the id 😞

NOTE: There are custom codes here that I don't give so make your own...

//--------------------------------------------------------
// Delete the webhook to avoid being called more than once 
//--------------------------------------------------------
string webhooks = api.Get("webhooks.json");
ShopifyWeebhook ShopifyWeebhook = JsonSerializer.Deserialize<ShopifyWeebhook>(webhooks);

if (ShopifyWeebhook.Webhooks.Length > 0)
{
    long WebhookId = ShopifyWeebhook.Webhooks.Last(w => w.Address.Contains("ShopifyBulkOperationWebhook", StringComparison.InvariantCultureIgnoreCase)).Id;
    string Result = api.Delete($"webhooks/{WebhookId}");
}