Webhook subscription failure for returns

We are looking at subscribing at all the webhooks related to returns but we are only able to subscribe to the topic “returns/update”. The subscription to all the following topics is rejected although they are marked as available in the API;

  • returns/cancel
  • returns/close
  • returns/decline
  • returns/reopen
  • returns/request

As an example the following request;

{
“webhook”: {
“address”: “https://z2zlknd7-5001.aue.devtunnels.ms/shopify/webhook”,
“topic”: “returns/reopen”
}
}

Generates the following error;

{
“errors”: “Could not find the webhook topic returns/reopen”
}

Can you please help investigate?

If you are trying to subscribe via the REST API those are unavailable for subscription via it.

See this for more information:

Got it. Thanks @RobDukarski.

1 Like

if not available for REST api Then How to subscribe returns/approve webhook in our custom app ?

Hi @Ramesh_Bissu

Can you use the GraphQL method described here: Webhooks?

1 Like

We need to register “returns/approve” return webhooks via GraphQl queries here the example may be work for you !
fetch all web hooks with graphql and register with graphql

// Function to fetch existing GraphQL webhooks
const getGraphQLWebhooks = async (shop, accessToken) => {
  const query = `
    {
      webhookSubscriptions(first: 100) {
        edges {
          node {
            topic
          }
        }
      }
    }
  `;

  const response = await axios.post(
    `https://${shop}/admin/api/2024-01/graphql.json`,
    { query },
    {
      headers: {
        "Content-Type": "application/json",
        "X-Shopify-Access-Token": accessToken,
      },
    }
  );

  const webhooks = response.data.data.webhookSubscriptions.edges.map(
    (w) => w.node.topic
  );
  return new Set(webhooks);
};

// Function to register GraphQL webhook
const registerGraphQLWebhook = async (shop, accessToken, topic, endpoint) => {
  const mutation = `
    mutation {
      webhookSubscriptionCreate(
        topic: ${topic.toUpperCase().replace("/", "_")}
        webhookSubscription: {
          callbackUrl: "${process.env.SHOPIFY_WEBHOOK_URL}${endpoint}"
          format: JSON
        }
      ) {
        webhookSubscription {
          id
        }
        userErrors {
          field
          message
        }
      }
    }
  `;

  const response = await axios.post(
    `https://${shop}/admin/api/2024-01/graphql.json`,
    { query: mutation },
    {
      headers: {
        "Content-Type": "application/json",
        "X-Shopify-Access-Token": accessToken,
      },
    }
  );

  // console.log("GraphQL Webhook Response:", response.data);
};
1 Like