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

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’,

url: ‘https://api.hubapi.com/crm/v3/objects/contacts’,

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

});

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

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’

};

console.log('===> request.get(\‘https://api.pipedream.com/v1/sources/dc_v3upnvA/event_summaries?expand=event)’);

let result = await request.get(‘https://api.pipedream.com/v1/sources/dc_v3upnvA/event_summaries?expand=event’, {

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.

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’,

url: `https://api.hubapi.com/crm/v3/objects/contacts?hapikey=${HUBSPOT\_API\_KEY}\`,

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 , this is great!

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

Hi @DCrowe ,

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