I’m trying to rename tickets in my HubSpot portal. The tickets that a created by integration are labeled “case created” and there are hundreds of them.
To fix it, I’m working on code in a Custom Workflow step to grab the text between two strings (“subject:” and “priority”) and put it in as the new ticket name.
Here’s a link to my code.
I think it may just be related to a typo in your code -- “inputfields” instead of “inputFields”. Regardless, here’s a simplified version of your example using HubSpot’s Node.Js client library (rather than axios).
const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({ "accessToken": process.env.your_hs_pat_secret_name });
exports.main = async (event, callback) => {
const content = event.inputFields['content']; // assumes this is a ticket-based workflow and ticket 'content' has been configured as a custom code 'property to include'
const matched = content.match(/Subject:\s*(.*?)\s*Priority:/);
const subject = matched ? matched[1] : "Not Found";
const ticketId = event.inputFields['hs_object_id']; // assumes this is a ticket-based workflow and ticket 'hs_object_id' has been configured as a custom code 'property to include'
const properties = {
"subject": subject
};
const SimplePublicObjectInput = { properties };
// update ticket
try {
const apiResponse = await hubspotClient.crm.tickets.basicApi.update(ticketId, SimplePublicObjectInput);
console.log(JSON.stringify(apiResponse, null, 2));
} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}
callback({
outputFields: {
matched: matched,
subject: subject
}
});
}
I hope that proves helpful. Please let me know if you have any follow-up questions.
Hi Zach,
Thank you for feedback. You’re right, I did have a typo. I updated it to “inputFields” then it worked - though I ran into different errors.
I tried your code and it gave me this error (and I believe I updated the code your provided correctly):
ERROR RequiredError: Required parameter ticketId was null or undefined when calling BasicApi.update.