Shopify Remix app and webhook auth problem

Hi, I’ve installed the remix app and created a dev store for creating orders.
For that I’ve created a test route with the following code

import { authenticate } from "../shopify.server";
export const action = async ({ request }) => {
const { shop, topic, payload, admin } = await authenticate.webhook(request);

console.log(`Received ${topic} webhook for ${shop} with payload: ${JSON.stringify(payload, null, 2)}`);

if (admin) {
  const response = await admin.graphql(
      `#graphql
      query {
          orders(first: 10) {
              edges {
              node {
                  id
                  updatedAt
              }
              }
          }
      }`
  );
  
  const orders = await response.json();
  console.log(`GraphQL response data: ${JSON.stringify(orders.data, null, 2)}`);
}

return new Response();
};

Now if I go to postman and create a post for that route I get nothing, then I’ve moved the code inside a try catch block

Now I get a response but is 400

I’m not sure what I’m doing wrong

Now if I go to postman and create a post for that route I get nothing, then I’ve moved the code inside a try catch block

Now I get a response but is 400

Most likely the problem is that Postman isn’t signing the requests with your private Shopify API key for your app.

Therefore, this line:

const { shop, topic, payload, admin } = await authenticate.webhook(request);

Is failing to authenticate, because your webhook is sent manually through Postman and isn’t signed like a proper webhook from Shopify would be.

You can simulate a webhook by registering one either in the Shopify admin dashboard for your development store, or registering one through the GraphQL API.

Then place an order through the online store checkout, or through a draft order. That will fire a proper webhook back to your app with the headers to authenticate against.

1 Like