Webhook Address Issue: Shopify Sometimes Hitting Incorrect URL

Hey everyone,

I’ve created a webhook subscription through the Shopify Admin API using the following code:

const webhookData: Webhook_POST = {  
    webhook: {  
        address: `https://xyz.com/v1/webhook/checkouts-delete?shop=${shopId}`,  
        format: 'json',  
        topic: topic,  
    },  
};  

await Axios.post(  
    `https://abc-shop.myshopify.com/admin/api/2023-07/webhooks.json`,  
    webhookData,  
    {  
        headers: {  
            'Content-Type': 'application/json',  
            'X-Shopify-Access-Token': accessToken,  
        },  
    }  
);

Initially, I mistakenly provided the webhook URL with double https (like https://https//xyz.com), but I corrected it to a single https soon after.

However, the issue is :

  • Sometimes Shopify still attempts to send requests to the incorrect double https URL (https://https//xyz.com/v1/webhook/checkouts-delete?shop=xxxxx), which results in a 503 Service Unavailable error.
  • Other times, it hits the correct endpoint (https://xyz.com/...) and works as expected with a 200 OK response.

I can’t figure out why Shopify is intermittently using the old, incorrect URL. Has anyone encountered this issue before or have insights into why this might be happening?

Hi @Aakanksha_Gupta,

If Shopify is unable to successfully send a webhook message it will retry sending that same webhook up to 8 times over the following 24 hours. My guess is the webhooks you’re seeing to the old URL are Shopify retrying those requests that were initiated when the old URL was configured.

For any new webhooks that are triggered, they should just go to the new URL that you configured. Does that match up with what you’re seeing?

Best,
Daniel

Hey @Daniel_Ablestar, whenever new webhooks are triggered, sometimes they are sent to the old URL and other times to the new URL. I don’t understand why this is happening.

Hi @Aakanksha_Gupta,

Initially, I mistakenly provided the webhook URL with double https (like https://https//xyz.com ), but I corrected it to a single https soon after.

Did you achieve this with a PUT request Webhook - REST

I’m asking because it sounds like you may have two subscriptions set up.

Run a GET request to check how many subscriptions are in place:
https://shopify.dev/docs/api/admin-rest/2024-10/resources/webhook#get-webhooks

1 Like

@leggetter , i have not used put request ,
i tried to run a GET request. i have provided X-Shopify-Access-Token in header ,
it is giving bad request for GET. but when i run post request , i am recieving the response.

Ok, so it sounds like you have two webhook subscriptions. One with the double https and the other correctly set up on.

Does your GET code look something like the following?

const webhookSubscriptions = await Axios.get(  
    `https://abc-shop.myshopify.com/admin/api/2023-07/webhooks.json`, 
    {  
        headers: {  
            'Content-Type': 'application/json',  
            'X-Shopify-Access-Token': accessToken,  
        },  
    }  
);

console.log(webhookSubscriptions);
1 Like

Hey, if i am sending like this then i am able to get response.
can you please tell me why i am getting bad request when i am sending it from postman.

Have you worked out if you have two subscriptions in place? Is that why you were getting webhooks sent to the older double https endpoint?

The cURL for the GET request generated from Postman is:

curl --location 'https://abc-shop.myshopify.com/admin/api/2024-10/webhooks.json?=' \
--header 'X-Shopify-Access-Token: {accessToken}'

1 Like

Thankyou so much . It worked, Yes, there were two webhook subscription.

1 Like

When you register webhooks programatically, especially during development or when testing different endpoints, its easy to end up with orphaned subscriptions that you forgot about. Shopify will happily deliver to all of them if they’re still active, which can cause exactly what you saw, webhooks seeming to hit the “wrong” url randomly.

A good habit is to periodically run a GET on your webhooks.json endpoint and audit what’s actually registered. I’ve seen cases where apps had three or four stale subscriptions pointing to old staging urls or previous versions of the callback path. If you’re using the Shopify CLI or an app template, sometimes webhooks get registered automatically during setup and its not always obvious. The Admin API docs have a section on managing webhook subscriptions that covers cleanup (https://shopify.dev/docs/apps/build/webhooks/subscribe).

For apps that rely heavily on webhooks for keeping data consistent, its worth considering whether a sync based approach might be simpler long term. Tools like Stacksync can keep your database updated in real time without managing individual subscriptions, though for your case the duplicate cleanup was probably all you needed. Hope this helps!