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

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

AdityaKumarJha
Visitor
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?

Replies 3 (3)

Alex
Shopify Staff
1561 81 342

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.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Commersys
Shopify Partner
4 0 0

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

renatomateusx
Shopify Partner
16 0 1

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();