I tried the following code:
const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({ accessToken: "access token" });
exports.main = async (event, callback) => {
const BatchInputPublicAssociationMultiPost = { inputs: [{"_from":{"id":"hs_ticket_id"},"to":{"id":"hs_object_id"},"types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":28}]}] };
const fromObjectType = "ticket";
const toObjectType = "deal";
try {
const apiResponse = await hubspotClient.crm.associations.batchApi.create(fromObjectType, toObjectType, BatchInputPublicAssociationMultiPost);
console.log(JSON.stringify(apiResponse, null, 2));
callback(null, apiResponse);
} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}
};
I received this error:
WARNING: The logs for this function have exceeded the 4KB limit.
...
ccurred.
Body: {"status":"error","message":"Invalid input JSON on line 1, column 65. Some required fields were not set: [type]","correlationId":"ee5746e3-451a-4f71-8a0b-597fabe647d8","category":"VALIDATION_ERROR"}
Headers: {"access-control-allow-credentials":"false","alt-svc":"h3=\":443\"; ma=86400","cf-cache-status":"DYNAMIC","cf-ray":"7da4d3faeb118260-IAD","connection":"close","content-length":"198","content-type":"application/json;charset=utf-8","date":"Tue, 20 Jun 2023 14:51:07 GMT","nel":"{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}","report-to":"{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=%2Bs0rt2rOl%2BQFKoBgCxB%2Fji6o6VVcd0TIMZ2sgkYtegT6Gg8C73DTWT2puW6iAehMWvOvSmwSUzhu4CqRen82Ilc%2BgEX%2B8ShF48a9zMGYoeVVZIyfGt4zL43VBmyxjpRv\"}],\"group\":\"cf-nel\",\"max_age\":604800}","server":"cloudflare","strict-transport-security":"max-age=31536000; includeSubDomains; preload","vary":"origin, Accept-Encoding","x-envoy-upstream-service-time":"16","x-evy-trace-listener":"listener_https","x-evy-trace-route-configuration":"listener_https/all","x-evy-trace-route-service-name":"envoyset-translator","x-evy-trace-served-by-pod":"iad02/hubapi-td/envoy-proxy-598c95b5b7-vk5c8","x-evy-trace-virtual-host":"all","x-hubspot-correlation-id":"ee5746e3-451a-4f71-8a0b-597fabe647d8","x-hubspot-ratelimit-daily":"500000","x-hubspot-ratelimit-daily-remaining":"499998","x-hubspot-ratelimit-interval-milliseconds":"10000","x-hubspot-ratelimit-max":"150","x-hubspot-ratelimit-remaining":"149","x-hubspot-ratelimit-secondly":"15","x-hubspot-ratelimit-secondly-remaining":"14","x-request-id":"3698e3b1-7651-46d3-9d8f-e664e6440333"}
at BatchApiResponseProcessor.<anonymous> (/opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/associations/apis/BatchApi.js:172:23)
at Generator.next (<anonymous>)
at fulfilled (/opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/associations/apis/BatchApi.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 400,
body: {
status: 'error',
message: 'Invalid input JSON on line 1, column 65. Some required fields were not set: [type]',
correlationId: 'ee5746e3-451a-4f71-8a0b-597fabe647d8',
category: 'VALIDATION_ERROR'
},
headers: {
'access-control-allow-credentials': 'false',
'alt-svc': 'h3=":443"; ma=86400',
'cf-cache-status': 'DYNAMIC',
'cf-ray': '7da4d3faeb118260-IAD',
connection: 'close',
'content-length': '198',
'content-type': 'application/json;charset=utf-8',
date: 'Tue, 20 Jun 2023 14:51:07 GMT',
nel: '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}',
'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=%2Bs0rt2rOl%2BQFKoBgCxB%2Fji6o6VVcd0TIMZ2sgkYtegT6Gg8C73DTWT2puW6iAehMWvOvSmwSUzhu4CqRen82Ilc%2BgEX%2B8ShF48a9zMGYoeVVZIyfGt4zL43VBmyxjpRv"}],"group":"cf-nel","max_age":604800}',
server: 'cloudflare',
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
vary: 'origin, Accept-Encoding',
'x-envoy-upstream-service-time': '16',
'x-evy-trace-listener': 'listener_https',
'x-evy-trace-route-configuration': 'listener_https/all',
'x-evy-trace-route-service-name': 'envoyset-translator',
'x-evy-trace-served-by-pod': 'iad02/hubapi-td/envoy-proxy-598c95b5b7-vk5c8',
'x-evy-trace-virtual-host': 'all',
'x-hubspot-correlation-id': 'ee5746e3-451a-4f71-8a0b-597fabe647d8',
'x-hubspot-ratelimit-daily': '500000',
'x-hubspot-ratelimit-daily-remaining': '499998',
'x-hubspot-ratelimit-interval-milliseconds': '10000',
'x-hubspot-ratelimit-max': '150',
'x-hubspot-ratelimit-remaining': '149',
'x-hubspot-ratelimit-secondly': '15',
'x-hubspot-ratelimit-secondly-remaining': '14',
'x-request-id': '3698e3b1-7651-46d3-9d8f-e664e6440333'
}
}
So, I’m not quite sure what I’m doing wrong. The code would be extremely helpful when you do have the time.
Thank you.