ERR_INVALID_ARG_TYPE issue with "data" argument being undefined

Highlighted
Shopify Partner
5 0 1

Hello!

I'm creating public Shopify app, node.js, react.js

The issue I'm having is with Webhooks! Default example app from GitHub and mine app have same issue.

I'm not receiving any triggers from Shopify when I test pay order on my test store or when I create new product (the webhooks I've registered).

When I try with Postman, I get this error:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, Buffer, TypedArray, or DataView. Received type undefined


I've checked the `.env.` file, everything looks normal. Like this: (not actual keys)

SHOPIFY_API_KEY='123123asaaasdasasd1123'
SHOPIFY_API_SECRET_KEY='342341adfasdffsd'
HOST='https://256b2fc9.ngrok.io/'
PORT='3000'
NODE_ENV='dev'


Of course everything else is working. Ngrok is free version.

Shop I'm using to test is nikola-development-test-store.myshopify.com

The whole error I receive is:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, Buffer, TypedArray, or DataView. Received type undefined
at Hmac.update (internal/crypto/hash.js:70:11)
at /home/dale/Desktop/POSAO/realitems/shopify/node_modules/@shopify/koa-shopify-webhooks/dist/src/receive.js:24:30
at step (/home/dale/Desktop/POSAO/realitems/shopify/node_modules/tslib/tslib.js:136:27)
at Object.next (/home/dale/Desktop/POSAO/realitems/shopify/node_modules/tslib/tslib.js:117:57)
at /home/dale/Desktop/POSAO/realitems/shopify/node_modules/tslib/tslib.js:110:75
at new Promise (<anonymous>)
at Object.__awaiter (/home/dale/Desktop/POSAO/realitems/shopify/node_modules/tslib/tslib.js:106:16)
at receiveWebhookMiddleware (/home/dale/Desktop/POSAO/realitems/shopify/node_modules/@shopify/koa-shopify-webhooks/dist/src/receive.js:14:24)
at dispatch (/home/dale/Desktop/POSAO/realitems/shopify/node_modules/koa-compose/index.js:44:32)
at next (/home/dale/Desktop/POSAO/realitems/shopify/node_modules/koa-compose/index.js:45:18)
at bodyParser (/home/dale/Desktop/POSAO/realitems/shopify/node_modules/koa-bodyparser/index.js:86:11)


Thank you!

P.S.

I've noticed that Shopify always use Topis like this: orders/create but @shopify/koa-shopify-webhooks use Topics like: ORDERS_CREATE

Why is that?

 

1 Like
Highlighted
Shopify Partner
5 0 1

UPDATE:

Issue is the same, I'm not receiving anything from Shopify at rest API endpoints I've provided for Webhooks.

When I query what webhooks are registered for test shop I get this:

[
  {
    node: {
      topic: 'ORDERS_CREATE',
      id: 'gid://shopify/WebhookSubscription/760126242861'
    }
  },
  {
    node: {
      topic: 'ORDERS_PAID',
      id: 'gid://shopify/WebhookSubscription/760126275629'
    }
  },
  {
    node: {
      topic: 'PRODUCTS_CREATE',
      id: 'gid://shopify/WebhookSubscription/760126308397'
    }
  }
]

So my webhook registration is okay...

0 Likes
Highlighted
Shopify Partner
28 1 5

@Realitems 

 

Did you ever get this resolved? I am getting the same issue with my registered webhooks.

 

Thanks!

1 Like
Highlighted
New Member
1 0 1

Ran into this issue for a long time eventually found out the culprit was bodyparser. I already found this code when bodyparser was breaking my graphql routes so I just had to add another rule to it for it not to also break the webhooks routes.

server.use(async (ctx, next) => {
    if (ctx.path === '/graphql' || ctx.path.includes('/webhooks')) {
      return await next();
    }
    await koaBody()(ctx, next);
  });

This just ensures that bodyparser won't run on routes with '/graphql' and '/webhooks'

1 Like
Highlighted
Shopify Partner
28 1 5

Hey @dan__  thanks for the response!

 

I forgot to add to this but that is the solution I came up with as well :) Removing the body parser for webhook routes will fix the issue.

0 Likes