Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HubSpotHanevold/86eb508f90d25112de3b40fe22ccdd80 to your computer and use it in GitHub Desktop.
Save HubSpotHanevold/86eb508f90d25112de3b40fe22ccdd80 to your computer and use it in GitHub Desktop.
const axios = require('axios');
exports.main = async (event, callback) => {
try {
// Replace with secret name
const auth = process.env.SAMPLESECRETNAME;
// Replace variables below as needed
const hsObjectId = event.inputFields['hs_object_id'];
const cpa = event.inputFields['cpa____'];
const campaignLaunchDate = event.inputFields['campaign_launch_date'];
const campaignEndDate = event.inputFields['campaign_end_date'];
const dealName = event.inputFields['dealname'];
// Need to look up the association ID for the custom object to the deal record (also create association between deal and custom object in UI)
// Set all properties to be copied in the array below.
const data = {
associations: [
{
types: [
{
associationCategory: 'USER_DEFINED',
associationTypeId: 97,
},
],
to: {
id: hsObjectId,
},
},
],
properties: {
campaign_end_date: campaignEndDate,
campaign_launch_date: campaignLaunchDate,
cpa____: cpa,
campaign_name: `${dealName} Campaign`,
},
};
// Replace the custom object ID 2-1006173 with the ID for your custom object.
const config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.hubapi.com/crm/v3/objects/2-21006173',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${auth}`,
},
data: JSON.stringify(data),
};
const response = await axios(config);
console.log(JSON.stringify(response.data));
} catch (error) {
console.error(error);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment