I'm creating a work flow to update all open deals to the company owner when a company owner is changed. The first step I have is creating code to get the company owner ID to be used later in assigned it to the open deals. I've included the code, inputs, and outputs, as well as the log. I've removed all actual information for anonymity, but the response come with the correct information. How can I store this information to use it in a later set of code to be assigned to the deals?
EDIT: Additionally, it says in my tests that the output variable is unassigned.
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
// Instantiate a new HubSpot API client using the API key (secret)
const hubspotClient = new hubspot.Client({
accessToken: process.env.hapikey
});
// Retrieve the company ID from the input fields
const companyId = event.inputFields['companyId'];
// Retrieve the company's "hubspot_owner_id" property
hubspotClient.crm.companies.basicApi.getById(companyId, ["hubspot_owner_id"])
.then(results => {
// Log the complete API response for debugging
console.log('API Response:', JSON.stringify(results, null, 2));
// Get the hubspot_owner_id from the results and store in a variable
let companyOwnerId = results.body.properties.hubspot_owner_id;
// Use the callback function to return the company owner ID
callback({
outputFields: {
companyOwnerId: companyOwnerId
}
});
InputsOuputs
2024-01-17T01:26:05.977Z INFO API Response: {
"id": "ID",
"properties": {
"createdate": "CREATEDATE",
"hs_lastmodifieddate": "2024-01-16T23:41:52.128Z",
"hs_object_id": "HS_OBJECT_ID",
"hubspot_owner_id": "HUBSPOT_OWNER_ID"
},
"createdAt": "2020-07-01T16:12:16.860Z",
"updatedAt": "2024-01-16T23:41:52.128Z",
"archived": false
}
2024-01-17T01:26:06.016Z ERROR Error occurred: TypeError: Cannot read properties of undefined (reading 'properties')
at /var/task/file.js:19:47
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Memory: 73/128 MB
Runtime: 1369.04 ms