APIs & Integrations

DCrowe
Member

How to extract specific data from a webhook payload using node JS, and POST that to my contacts in .

SOLVE

I have built a node js app inorder to integrate vend and hubspot. I can use the following post route to add contacts to my test account.  However what I want is take the relevant data from a vend webhook and post that to hubspot. this current set up won't allow that type of dynamic data.

 

const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: 'Bearer xxxxx xxxxx xxxx xxxx xxxxx xxxxxx xxxxx xxxx xxxx xxxxx xxxxx '},
body: {
properties: {
company: "Big",
email: 'ooper@Riglytics.net',
firstname: `Wresult`,
lastname: 'ooper',
phone: '(3877) 929-0687',
website: 'iglytics.net'
}
},
json: true
};

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});
0 Upvotes
1 Accepted solution
DCrowe
Solution
Member

How to extract specific data from a webhook payload using node JS, and POST that to my contacts in .

SOLVE

Hey just a heads up, I came across a solution, it still needs refinement but is much closer to what I am trying to acheive.

 

const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
},
body: {
properties: {
company: webhook.root.payload.outlet.name,
email: 'aZZzooper@Riglytics.net',
firstname: webhook.root.payload.outlet.name,
lastname: webhook.root.payload.outlet.name,
phone: '(331377) 929-0687',
website: '3eweiglzytics.net'
}
},
json: true
};

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});
res.status(201).json("OK - Hubspot was updated");
} catch (error) {
console.log(error);
return res.status(500).send("GREAT error").end();
}
});


View solution in original post

5 Replies 5
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

How to extract specific data from a webhook payload using node JS, and POST that to my contacts in .

SOLVE

Hi @DCrowe ,

 

For your information there is an official nodeJs SDK released some day ago npm repository 


0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

How to extract specific data from a webhook payload using node JS, and POST that to my contacts in .

SOLVE

@DCrowe , this is great!

Post your final code here and accept it as a solution so others can take advantage of your work 😀

0 Upvotes
DCrowe
Solution
Member

How to extract specific data from a webhook payload using node JS, and POST that to my contacts in .

SOLVE

Hey just a heads up, I came across a solution, it still needs refinement but is much closer to what I am trying to acheive.

 

const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
},
body: {
properties: {
company: webhook.root.payload.outlet.name,
email: 'aZZzooper@Riglytics.net',
firstname: webhook.root.payload.outlet.name,
lastname: webhook.root.payload.outlet.name,
phone: '(331377) 929-0687',
website: '3eweiglzytics.net'
}
},
json: true
};

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});
res.status(201).json("OK - Hubspot was updated");
} catch (error) {
console.log(error);
return res.status(500).send("GREAT error").end();
}
});


DCrowe
Member

How to extract specific data from a webhook payload using node JS, and POST that to my contacts in .

SOLVE

Hey dennisedon, so at the moment I am sending the webhook to pipedream while in development, my get route can get a payload.

 

get vend web hook payload
const getPageInfo = async (accessToken) => {
// console.log('');
console.log('=== Retrieving payload from Vend using the access token ===');
try {
let headers = {
Authorization: `Bearer ${PIPEDREAM_TOKEN}`,
'Content-Type': 'application/json'
};
headers: headers
});
// console.log(result);
return JSON.parse(result).data[0];
} catch (e) {
console.error(' > Unable to retrieve deals');
return JSON.parse(e.response.body);
}
};

Where I am stuck is getting this payload and posting it to hubspot. I have watched all the relevant videos in the academy and scoured stack overflow but can't find an answer.
0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

How to extract specific data from a webhook payload using node JS, and POST that to my contacts in .

SOLVE

Hey @DCrowe 

What info are you trying to get from vend?  How are you dealing with the payload they send you?

@quentin_lamamy , do you ideas?  I feel like we need some more information to properly help here

0 Upvotes