Solved

Unabel to trigger Mandatory Webhooks on Node Template

samir_al_anabi
Shopify Partner
6 2 0

Hi

i am working on shopify application with default Node template. I am trying to setup mandatory webhooks. Just for sake of clarity see the below code

deliveryMethod: DeliveryMethod.Http,
    callbackUrl: "/api/webhooks",
    callback: async (topic, shop, body, webhookId) => {
      logger.info('CUSTOMERS_DATA_REQUEST called')
      // const payload = JSON.parse(body);
      // logger.info({
      //   Body: payload
      // }, 'CUSTOMERS_DATA_REQUEST called')
      const dataRequestHandler = new CustomersDataRequestHandler(new CustomersDataRequest(topic, body))
      await dataRequestHandler.handle()

      // const sessionId = await shopify.api.session.getOfflineId(shop)
      // const session = await shopify.config.sessionStorage.loadSession(sessionId);
      // Payload has the following shape:
      // {
      //   "shop_id": 954889,
      //   "shop_domain": "{shop}.myshopify.com",
      //   "orders_requested": [
      //     299938,
      //     280263,
      //     220458
      //   ],
      //   "customer": {
      //     "id": 191167,
      //     "email": "john@example.com",
      //     "phone": "555-625-1199"
      //   },
      //   "data_request": {
      //     "id": 9999
      //   }
      // }
    },
  },

When i goto to linked Dev store, then customer and request any customer's data. i see following message at console

Session was not valid. Redirecting to /api/auth?shop=undefined | {shop: undefined}
11:28:51 │ web-backend  │ [shopify-api/ERROR] Missing Authorization header, was the request made with authenticatedFetch? | {isOnline: false}

I don't understand why is doesn't work. See below webhook config

[webhooks.privacy_compliance]
  customer_deletion_url = "https://crab-model-briefly.ngrok-free.app/api/webhooks/customer_deletion"
  customer_data_request_url = "https://crab-model-briefly.ngrok-free.app/api/webhooks/customer_request"
  shop_deletion_url = "https://crab-model-briefly.ngrok-free.app/api/webhooks/deletion"

package.json

"dependencies": {
    "@shopify/app": "3.58.2",
    "@shopify/cli": "3.59.0"
  }
Accepted Solution (1)

samir_al_anabi
Shopify Partner
6 2 0

This is an accepted solution.

I was using wrong URL like in

https://crab-model-briefly.ngrok-free.app/api/webhooks/customer_deletion

"customer_deletion" shouldn't be there

View solution in original post

Reply 1 (1)

samir_al_anabi
Shopify Partner
6 2 0

This is an accepted solution.

I was using wrong URL like in

https://crab-model-briefly.ngrok-free.app/api/webhooks/customer_deletion

"customer_deletion" shouldn't be there