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

i have no "topic" property in the payload. (SUPER NOOB QUESTION)

i have no "topic" property in the payload. (SUPER NOOB QUESTION)

massiv
Shopify Partner
7 0 3

So this is the code i get when i first create an app with shopify cli (with some small variations) 

 

 

 

export const action = async ({ request }) => {
  console.log("ejecutando request webhook");
  /* Verificamos que sea un webhook válido de Shopify
  if (!verifyShopifyWebhook(request)) {
    return json({ message: "Unauthorized" }, { status: 401 });
  }
*/
  const payload = await request.json(); // Obtenemos el payload del webhook
  console.log(payload);
  if (payload.topic === "app/uninstalled") {
    console.log("App desinstalada", payload);
    // Lógica para manejar la desinstalación
  } else if (payload.topic === "app_purchases_one_time/update") {
    console.log("Compra de app actualizada", payload);
    // Lógica para manejar la actualización de compras
  }
  console.log("pinto", payload);
  // Siempre devolver una respuesta
  return json({ message: "Webhook recibido correctamente" });

  const { topic, shop, session, admin } = await authenticate.webhook(request);
  console.log("esto nunca pasa", topic);
  if (!admin && topic !== "SHOP_REDACT") {
    // The admin context isn't returned if the webhook fired after a shop was uninstalled.
    // The SHOP_REDACT webhook will be fired up to 48 hours after a shop uninstalls the app.
    // Because of this, no admin context is available.
    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 "APP_PURCHASES_ONE_TIME_UPDATE":
      console.log("COMPRARON UNA VEZ");
      break;
    case "CUSTOMERS_DATA_REQUEST":
    case "CUSTOMERS_REDACT":
    case "SHOP_REDACT":
    default:
      throw new Response("Unhandled webhook topic", { status: 404 });
  }

  throw new Response();
};

 

 
and this is what i have if i print the Payload:
 
 

 

{
 app_purchase_one_time: {
 admin_graphql_api_id: 'gid://shopify/AppPurchaseOneTime/3120824564',
 name: '4 AI Videos',
 status: 'ACTIVE',
 admin_graphql_api_shop_id: 'gid://shopify/Shop/71627636980',
 created_at: '2024-09-12T12:14:16-04:00',
 updated_at: '2024-09-12T12:14:23-04:00'
 }
 }

 

 
 
 So my question is simple... WHERE IS TOPIC??? none of those cases will trigger (i think) because there is no payload.topic. Right? what am i missing here?

 

Replies 0 (0)