BULK_OPERATIONS_FINISH webhook topic is not fired back

AlexanderKushch
Shopify Partner
3 0 0

I'm developing an app for Shopify using a remix template. The documentation states that for such templates, subscription to webhook topics occurs by adding the webhook configuration to the shopifyApp function:

 

 

  webhooks: {
    APP_UNINSTALLED: {
      deliveryMethod: DeliveryMethod.Http,
      callbackUrl: "/webhooks",
    },
    BULK_OPERATIONS_FINISH: {
      deliveryMethod: DeliveryMethod.Http,
      callbackUrl: "/webhooks"
    }
  },
  hooks: {
    afterAuth: async ({ session }) => {
      shopify.registerWebhooks({ session });
    },
  },

 

 

And this is my query for bulk operation:

 

 

export const getOrdersBulk = `
  mutation {
    bulkOperationRunQuery(
      query: """
      {
        orders {
          edges {
            node {
              id
              createdAt
              netPaymentSet {
                shopMoney {
                  amount
                  currencyCode
                }
              }
              fullyPaid
            }
          }
        }
      }
      """
    ) {
      bulkOperation {
        id
        status
      }
      userErrors {
        field
        message
      }
    }
}`;

 

 

Query completes, and in response i get { id: 'gid://shopify/BulkOperation/3964961849649', status: 'CREATED' };

But webhook BULK_OPERATIONS_FINISH is not firing at all. Can you help me, maybe i get something wrong?

Replies 3 (3)

921Kiyo
Shopify Partner
15 0 1

I am facing the same issue. BULK_OPERATIONS_FINISH webhook is not firing. Did anyone find out what could be wrong?

AlexanderKushch
Shopify Partner
3 0 0

Yes, i`m solved it. My problem was in webhook registration mechanism. By default webhooks registration happens in hook afterAuth at example, that i provided in first message. When you starded dev script, you can reinstall the app, for webhooks second registration.
For now i`m looking for a better solution, but for now it works:

 

export async function loader({ request }) {
  const { session } = await authenticate.admin(request);
  await shopify.registerWebhooks({ session });

  return json({
    polarisTranslations: require('@shopify/polaris/locales/en.json'),
    apiKey: process.env.SHOPIFY_API_KEY,
  });
}

 

in root.tsx loader, i`m just calling shopify.registerWebhooks, and it works fine.
Originally, i got this answer from twitter user with nickname: kinngh .
I hope this helps you)

921Kiyo
Shopify Partner
15 0 1

Thanks, I ended up calling registerWebhooks inside the shopify.server (I am using remix framework btw). 

import "@shopify/shopify-app-remix/adapters/node";
import {
  AppDistribution,
  DeliveryMethod,
  shopifyApp,
  LATEST_API_VERSION,
} from "@shopify/shopify-app-remix/server";
import { PrismaSessionStorage } from "@shopify/shopify-app-session-storage-prisma";
import { restResources } from "@shopify/shopify-api/rest/admin/2023-10";

const shopify = shopifyApp({
  apiKey: process.env.SHOPIFY_API_KEY,
  apiSecretKey: process.env.SHOPIFY_API_SECRET || "",
  apiVersion: LATEST_API_VERSION,
  scopes: process.env.SCOPES?.split(","),
  appUrl: process.env.SHOPIFY_APP_URL || "",
  authPathPrefix: "/auth",
  sessionStorage: new PrismaSessionStorage(prisma),
  distribution: AppDistribution.AppStore,
  restResources,
  webhooks: {
    APP_UNINSTALLED: {
      deliveryMethod: DeliveryMethod.Http,
      callbackUrl: "/webhooks",
    },
    BULK_OPERATIONS_FINISH: {
      deliveryMethod: DeliveryMethod.Http,
      callbackUrl: "/xxx",
    },
  },
  hooks: {
    afterAuth: async ({ session }) => {
      shopify.registerWebhooks({ session });
    },
  },
  future: {
    v3_webhookAdminContext: true,
    v3_authenticatePublic: true,
  },
  ...(process.env.SHOP_CUSTOM_DOMAIN
    ? { customShopDomains: [process.env.SHOP_CUSTOM_DOMAIN] }
    : {}),
});