How can I create webhook through rest api in NODE js ?

Highlighted
New Member
1 0 0

How can I create webhook throush rest api in NODE js ? I found this solution on docs

 

app.post('URL', (requestresponse=> {
  response.send({
    "webhook": {
      "topic""orders/create",
      "address""https://whatever.com",
      "format""json"
    }
  });
});

 

Can anyone please teach me how to implement this on shopify node app and to what URL should I make POST request throush REST api?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1555 81 282

You would POST to https://shop_domain.myshopify.com/admin/api/2019-10/webhooks.json, this is clearly outlined in the documentation.

 

You could do this a number of ways when using Node:

 

I'm not a JS developer myself, so you probably don't want any specific code examples I would share, but the above should be adequate for finding your own way.

 

Cheers and good luck.

0 Likes
Highlighted
Shopify Partner
4 0 0

what should come in the header of this api call? access token ?

0 Likes
Highlighted
Shopify Partner
14 0 0

I'm trying to create a webhook with nodejs, but receiving this error:

 

getaddrinfo EAI_FAIL https://api_key:pass@url_store
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {
errno: 'EAI_FAIL',
code: 'EAI_FAIL',
syscall: 'getaddrinfo',
hostname: 'https://api_key:pass@url_store'
}

 

 

this is my request code

 

var postData = querystring.stringify(body);
    var options = {
      hostname: url,
      port: 443,
      path: path,
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Content-Length': postData.length
      }
    };
    var req = https.request(options, (res=> {
      console.log('statusCode:'res.statusCode);
      console.log('headers:'res.headers);
      res.on('data', (d=> {
        resolve(d);
      });

    });
    req.on('error', (e=> {
      reject(e);
    });

    req.write(postData);
    req.end();
0 Likes