Hi guys,
I am trying to change a property price_per_month which is currency string to a number, which I managed. And then overwrite this property by another pricing_price and add to contact so every contact which get currency string is then changed to number and assigned as pricing price so I can have it in my benchmarking afterwards for analyze.
Can anyone help?
I have this, but apparently there are errors…
const hubspot = require(‘@hubspot/api-client’);
var price_per_month;
var pricing_price;
var cur_re = /\D*(\d+|\d.*?\d)(?:\D+(\d{2}))?\D*$/;
var parts = cur_re.exec(price_per_month);
var number = parseFloat(parts[1].replace(/\D/,‘’)+‘.’+(parts[2]?parts[2]:‘00’));
pricing_price = number.toFixed(2);
exports.main = (event, callback) => {
callback(processEvent(event));
};
function processEvent(event) {
const hubspotClient = new hubspot.Client({ apiKey: process.env.HAPIKEY });
let engage_id = event[‘price_per_month’];
// console.log(engage_id);
hubspotClient.crm.objects.basicApi
.getById(event.object.objectType, event.object.objectId, [“pricing_price”])
.then(results => {
let engage_enroll = results.body;
console.log(engage_enroll)
hubspotClient.crm.objects.associationsApi
.getAll(
event.object.objectType,
event.object.objectId,
[“contacts”]
)
.then(results => {
let associations = results.body.results;
let contact_ids = associations.map(a => a.id);
console.log(associations, contact_ids);
contact_ids.forEach(function (entry) {
hubspotClient.apiRequest({
method: ‘POST’,
path: `/automation/v2/workflows/22041022/enrollments/contacts/${entry}?hapikey=${process.env.HAPIKEY}`
});
});
}
)
}
)
}