Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

shopify app dev improperly configures webhook addresses

Solved

shopify app dev improperly configures webhook addresses

hydrocat
Shopify Partner
4 1 5

I followed the scaffolding app tutorial: https://shopify.dev/docs/apps/build/scaffold-app
This tutorial guides me to the next one, https://shopify.dev/docs/apps/build/build?framework=remix

 

When I run `shopify app deploy`, the example app works as expected, but the webhooks use the wrong endpoint.

 

having both guides done, I added a log to `app/routes/webhooks.js`:

import { authenticate } from "../shopify.server";
import db from "../db.server";

export const action = async ({ request }) => {
  const { topic, shop, session, admin } = await authenticate.webhook(request);

  concole.log("Hook received!!!")
  console.log([
    topic, shop, session, admin
  ]);

  if (!admin) {
    // The admin context isn't returned if the webhook fired after a shop was uninstalled.
    throw new Response();
  }

  // The topics handled here should be declared in the shopify.app.toml.
  // More info: https://shopify.dev/docs/apps/build/cli-for-apps/app-configuration
  switch (topic) {
    case "APP_UNINSTALLED":
      if (session) {
        await db.session.deleteMany({ where: { shop } });
      }

      break;
    case "CUSTOMERS_DATA_REQUEST":
    case "CUSTOMERS_REDACT":
    case "SHOP_REDACT":
    default:
      throw new Response("Unhandled webhook topic", { status: 404 });
  }

  throw new Response();
};

 

 

in the config.toml, I added:

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = "read_orders,write_products"


[webhooks]
api_version = "2024-07"

[[webhooks.subscriptions]]
topics = [
"app/uninstalled",
"orders/create",
"orders/fulfilled",
"orders/paid"
]
uri = "/webhooks"

I filled the user data request as necessary for this development app.

 

After `shopify app dev`, I open the store and purchase something, pay it and process it. These actions should generate webrequests to my app.

In fact, when I open the app's dashboard I see a lot of failed requests.

 

hydrocat_0-1723217675911.pnghydrocat_1-1723217751307.png

 

From the images I see that the requests were made to

`https://distant-done-cameron-protect.trycloudflare.com/webhooks`

which is an auto-generated domain name.

 However, when I open the toml file, I see that the CLI has updated the urls with another address from cloudfare!

 

[auth]
redirect_urls = [
"https://jamie-joins-ken-vulnerable.trycloudflare.com/auth/callback", # changes with every `shopify app dev`
"https://jamie-joins-ken-vulnerable.trycloudflare.com/auth/shopify/callback",
"https://jamie-joins-ken-vulnerable.trycloudflare.com/api/auth/callback"
]

 

From my understanding, the command `shopify app dev` should setup a cloudfare address and update my app's config. That config then gets pushed to shopify. And it does (see the picture)

hydrocat_2-1723217975192.png

 However, the webhook addresses are somehow not updated.

can you help me ?

Accepted Solution (1)

hydrocat
Shopify Partner
4 1 5

This is an accepted solution.

Searching more, I found out that you have to npm run shopify app dev and while that is running, do  npm run shopify app deploy.

 

dev makes the cloudflare tunnel. While that is running, deploy sends the app status to shopify (with the right tunnel)

 

View solution in original post

Replies 3 (3)

hydrocat
Shopify Partner
4 1 5

To put it simply,
the command npm run shopify app deploy submits a temporary cloudflare url to the shopify app configuration, later, npm run shopify app dev sets up another cloudflare address and starts the app.
What happens then is that the webooks use the address from deploy and not from dev.

 

Not sure how to fix this, perhaps modifying the CLI's source code ?

hydrocat
Shopify Partner
4 1 5

This is an accepted solution.

Searching more, I found out that you have to npm run shopify app dev and while that is running, do  npm run shopify app deploy.

 

dev makes the cloudflare tunnel. While that is running, deploy sends the app status to shopify (with the right tunnel)

 

stefanb1234
Shopify Partner
19 0 9

It's very strange. I remember a couple months back that you would not need to run deploy when using app dev. Has that been changed? I feel lik this is a huge downside for DX