Hi!
Im new to hubspot crm, but trying to make one simple thing. I have created the extension that just make document files, now i need data for this files. I want to get it from Deal associations. I have custom object - it represents the products associated with the deal. So, everything I want just to fetch the list of the products.
My card use call to serverless function, main data it passes without problem, so I assume I make it works. But I stuck with getting the products. I tried this request right in the sandobx of documenation
/crm/v4/objects/{objectType}/{objectId}/associations/{toObjectType}
I put my token and objectType, objectId and toObjectType to the sandbox and it works. I see the results in sandbox below. So, I copied the code from it to my serverless function and I can’t make a request, because getting
ERROR - TypeError: Cannot read properties of undefined (reading ‘basicApi’)
at exports.main (/var/task/test.js:66:47)
at exports.hubspot_handler [as handler] (/var/task/hubspotHandler.js:20:34)
at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1187:29)
I google a lot and find that there was a problem with Node.js, but it was in 2023. So, I hope they have fixed it already. I tried to create a simple fetch requests to v3 and v4 api and didn’t get results in it. All the times some kind of errors. So, can somebody please share how you guys fetching the associations details with hubspot SDK or without.
I even tried this:
async function getAssociatedRecords({
objectType,
objectId,
toObjectType,
token,
}) {
const path = `/crm/v4/objects/${objectType}/${objectId}/associations/${toObjectType}`;
return new Promise((resolve, reject) => {
const options = {
method: "GET",
hostname: "api.hubapi.com",
path,
headers: {
accept: "application/json",
"content-type": "application/json",
authorization: "Bearer " + token,
},
};
const req = https.request(options, (res) => {
let chunks = \[];
res.on("data", (chunk) => chunks.push(chunk));
res.on("end", () => {
const body = Buffer.concat(chunks).toString();
console.log(" Status Code:", res.statusCode);
console.log(" Raw Body:", body);
if (!body \|\| body.trim() === "") {
return reject({
message: "Empty response body",
statusCode: res.statusCode,
});
}
try {
const parsed = JSON.parse(body);
resolve(parsed);
} catch (err) {
reject({ message: "Failed to parse JSON", raw: body });
}
});
});
req.on("error", (err) => reject(err));
req.end();
});
}
but still no luck