Shopify / cli

Build apps, themes, and hydrogen storefronts for Shopify
https://shopify.dev
MIT License
437 stars 130 forks source link

[Bug]: Declarative webhook not triggers #4666

Open akospaska opened 1 month ago

akospaska commented 1 month ago

Please confirm that you have:

In which of these areas are you experiencing a problem?

App

Expected behavior

App/uninstalled webhook fires.

Actual behavior

App/uninstalled webhook doesn't fire.

Verbose output

Hello Guys,

We are using declarative webhooks to register webhook endpoints. This is a great feature which saves us a lots of time and we don't have to bother the webshop's webhooks management.

However We have experienced the app/uninstalled webhook not triggers, only just sometimes.

Here is the toml file what we are using.

client_id = "31a617c50c7b2314dc483dafb7d71f31"
name = "test"
application_url = "https://6bac0dba9da2.ngrok.app"
embedded = true

[build]
automatically_update_urls_on_dev = true
dev_store_url = "checkoutintegrationdev.myshopify.com"
include_config_on_deploy = true

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = "read_assigned_fulfillment_orders,read_fulfillments,read_merchant_managed_fulfillment_orders,read_orders,read_third_party_fulfillment_orders,write_assigned_fulfillment_orders,write_fulfillments,write_merchant_managed_fulfillment_orders,write_orders,write_products,write_third_party_fulfillment_orders"

[auth]
redirect_urls = [
  "https://6bac0dba9da2.ngrok.app/auth/callback",
  "https://6bac0dba9da2.ngrok.app/auth/shopify/callback",
  "https://6bac0dba9da2.ngrok.app/api/auth/callback"
]

[webhooks]
api_version = "2024-10"

  [[webhooks.subscriptions]]
  topics = [ "app/uninstalled" ]
  uri = "/api/v1/webhook/app/uninstalled"

  [[webhooks.subscriptions]]
  topics = [ "app_subscriptions/update" ]
  uri = "/api/v1/webhook/appsubscriptions/update"

  [[webhooks.subscriptions]]
  topics = [ "orders/create" ]
  uri = "/api/v1/webhook/orders/create"

  [[webhooks.subscriptions]]
  topics = [ "orders/delete" ]
  uri = "/api/v1/webhook/orders/delete"

  [[webhooks.subscriptions]]
  topics = [ "orders/updated" ]
  uri = "/api/v1/webhook/orders/updated"

[pos]
embedded = false

All of the other webhooks have fired as expected.

I have also get the registered webhooks via API but it returns an empty array. https://.myshopify.com/admin/api/2024-10/webhooks.json

So I assume the declarative webhooks are different things as the normal webhook registrations.

I have dig deep into the Shopify CLI source code but I couldn't find where the issue can be.

I have checked the ngrok logs and I see all of the webhooks endpoint have been called, only the app/uninstalled is missing.

We have an another application which runs in production 2.5 years long, and we manage the shop's webhooks registration with API calls and it works fine.

  1. Is there a way to check which webhooks have been registered as declarative?
  2. How should i use the toml file to register every time the app/uninstalled webhooks as well?

I have seen not the same but sort of part of the issue here allready: https://github.com/Shopify/shopify-app-template-remix/issues/818

There are couple of suggestions to 'shopify app deploy -- --reset' and so on. My problem is we are almost ready and want to be launched the application. I don't see how can or should I call the shopify app deploy by every uninstall, however the shopify app deploy -- --reset doesn't solve my issue locally.

Thank you guys all of your help in advance!

Ákos

Reproduction steps

  1. Start the ngrok tunnel
  2. Write the toml file with webhooks
  3. Shopify app deploy
  4. Install the app to the test store
  5. Uninstall the app from the test store
  6. Get the app/uninstalled webhook trigger event as expected
  7. Install the app again to the test store
  8. Try order updated webhook and it works as expected.
  9. Uninstall the app from the test store
  10. And the app/uninstalled webhook not firing

Operating System

ubuntu

Shopify CLI version (check your project's package.json if you're not sure)

3.64.1

Shell

No response

Node version (run node -v if you're not sure)

v20.9.0

What language and version are you using in your application?

Express+ react

FynnMenkIT commented 1 month ago

Same Same but different issue here.

Situation: We already have our webhooks working via the old hook in the shopify.server.ts . The only problem is that we really want to avoid reinstalling the app in the live environment. The webhooks the way they are registered in the old way are only register with a new reinstall as far as I know.

Problem The way to register webhooks in the toml would help our scenario. But with the following files, the webhooks wont register on deploy or with shopify app dev --reset . The only webhook registering is app/uninstalled and this only sometimes if I also reinstall the Application. I also played around with /test-endpoint or /webhooks in the shopify.app.toml and in the shopify.web.toml.

This is our shopify.app.toml:

...
[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = "read_cart_transforms,read_checkout_branding_settings,read_discounts,read_payment_customizations,write_cart_transforms,write_checkout_branding_settings,write_discounts,write_payment_customizations,write_products"
[webhooks]
api_version = "2024-07"

  [[webhooks.subscriptions]]
  topics = [ "app/uninstalled" ]
  uri = "/webhooks"
  [[webhooks.subscriptions]]
  topics = [ "discounts/create" ]
  uri = "/test-endpoint"
  [[webhooks.subscriptions]]
  topics = [ "discounts/update" ]
  uri = "/test-endpoint"
  [[webhooks.subscriptions]]
  topics = [ "discounts/delete" ]
  uri = "/test-endpoint"
...

This is our web.app.toml (I dont know why it should be like this, or if i forget something)

name = "remix"
roles = ["frontend", "backend"]
webhooks_path = "/webhooks/app/uninstalled"

[commands]
dev = "npx prisma generate && npx prisma migrate deploy && npm exec remix vite:dev"
predev = "npx prisma generate"

This is our package.json (maybe important because of versions)

...
  "type": "module",
  "engines": {
    "node": "^18.20 || ^20.10 || >=21.0.0"
  },
  "dependencies": {
    "@prisma/client": "^5.8.0",
    "@remix-run/dev": "^2.7.1",
    "@remix-run/node": "^2.7.1",
    "@remix-run/react": "^2.7.1",
    "@remix-run/serve": "^2.7.1",
    "@shopify/app-bridge-react": "^4.1.2",
    "@shopify/cli": "^3.63.1",
    "@shopify/polaris": "^12.0.0",
    "@shopify/shopify-app-remix": "^3.3.2",
    "@shopify/shopify-app-session-storage-prisma": "^5.0.2",
    "isbot": "^5.1.0",
    "prisma": "^5.8.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "vite-tsconfig-paths": "^5.0.1"
  },
  "devDependencies": {
    "@remix-run/eslint-config": "^2.7.1",
    "@shopify/api-codegen-preset": "^1.1.1",
    "@types/eslint": "^8.40.0",
    "@types/node": "^22.2.0",
    "@types/react": "^18.2.31",
    "@types/react-dom": "^18.2.14",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.1.0",
    "prettier": "^3.2.4",
    "typescript": "^5.2.2",
    "vite": "^5.1.3"
  },
  "workspaces": [
    "extensions/*"
  ],
  "trustedDependencies": [
    "@shopify/plugin-cloudflare"
  ],
  "resolutions": {
    "string-width": "4.2.3"
  },
...
gonzaloriestra commented 2 weeks ago

Hi! Sorry for the late response.

This answer may help: https://community.shopify.dev/t/app-uninstalled-webhook-inconsistently-subscribed-fired/685?u=zzooeeyy