const hubspotClient = new Hubspot.Client({"developerApiKey":"key"});
async function registerWorkflowExtension(accessToken) {
const PublicActionDefinitionEgg = {
"functions": [],
"actionUrl": `${url}/workflow/trigger`,
"published": true,
"labels": {
"en": {
"inputFieldDescriptions": {
"phone_number": "Contact's phone number",
"channel": "Which channel to use",
"message": "Message text with optional personalization tokens"
},
"outputFieldLabels": {
"status": "Send Status"
},
"actionDescription": "Send an SMS or WhatsApp message from a workflow",
"inputFieldLabels": {
"phone_number": "Phone Number",
"channel": "Channel",
"message": "Message"
},
"actionName": "Send SMS/WhatsApp",
"actionCardContent": "This action sends an SMS or WhatsApp message using SendMetrix"
}
},
"inputFields": [
{
"isRequired": true,
"automationFieldType": "string",
"typeDefinition": {
"helpText": "The destination phone number. Can use a contact property.",
"referencedObjectType": null,
"name": "phone_number",
"options": [],
"description": "Contact's phone number",
"externalOptionsReferenceType": null,
"label": "Phone Number",
"type": "string",
"fieldType": "text",
"optionsUrl": null,
"externalOptions": false
},
"supportedValueTypes": [
"STATIC_VALUE"
]
},
{
"isRequired": true,
"automationFieldType": "string",
"typeDefinition": {
"helpText": "Choose SMS or WhatsApp",
"referencedObjectType": null,
"name": "channel",
"options": [
{
"label": "SMS",
"value": "sms"
},
{
"label": "WhatsApp",
"value": "whatsapp"
}
],
"description": "Select delivery channel",
"externalOptionsReferenceType": null,
"label": "Channel",
"type": "enumeration",
"fieldType": "select",
"optionsUrl": null,
"externalOptions": false
},
"supportedValueTypes": [
"STATIC_VALUE"
]
},
{
"isRequired": true,
"automationFieldType": "string",
"typeDefinition": {
"helpText": "Your message. Supports tokens like {{ contact.firstname }}.",
"referencedObjectType": null,
"name": "message",
"options": [],
"description": "Text content of the message",
"externalOptionsReferenceType": null,
"label": "Message",
"type": "string",
"fieldType": "text",
"optionsUrl": null,
"externalOptions": false
},
"supportedValueTypes": [
"STATIC_VALUE"
]
}
],
"outputFields": [
{
"typeDefinition": {
"helpText": "Message delivery status",
"referencedObjectType": null,
"name": "status",
"options": [],
"description": "Status of message sending",
"externalOptionsReferenceType": null,
"type": "string",
"fieldType": "text",
"optionsUrl": null,
"externalOptions": false
}
}
],
"objectTypes": [
"CONTACT"
]
};
try {
// const reg = await axios.post(
// '
https://api.hubapi.com/automationextensions/v1/extensions',
// payload,
// { headers: { Authorization: `Bearer ${accessToken}` } }
// );
const appId = 17385118; // your HubSpot app ID, numeric
// const response = await axios.post(
// `
https://api.hubapi.com/automation/v4/actions/${appId}`,
// actionDefinition,
// {
// headers: {
// Authorization: `Bearer ${accessToken}`,
// 'Content-Type': 'application/json'
// }
// }
// );
const apiResponse = await hubspotClient.automation.actions.definitionsApi.create(appId, PublicActionDefinitionEgg);
// console.log(JSON.stringify(apiResponse, null, 2));
// console.log('Direct axios registration success:', apiResponse);
console.log('Workflow extension created:', JSON.stringify(apiResponse, null, 2));
// Optionally, you can store the created action definition ID for later use
const actionId = apiResponse.id;
// console.log("Workflow extension registered:", reg.data);
return true;
} catch (error) {
console.error('Extension registration error:', error.response?.data || error.message);
return false;
}
}
still not working please checkwhy?
or one more detail that can help
/automation/v4/actions/17385118
header:
{
"cf-ipcountry": [
"IN"
],
"true-client-ip": [
"122.176.33.160"
],
"User-Agent": [
"got (
https://github.com/sindresorhus/got)"
],
"Accept-Encoding": [
"gzip"
],
"X-HubSpot-Proxied-Source-Hublet": [
"na2"
],
"X-HubSpot-Trace": [
"177529a4ecd06e4f83e85ce6fcbb5cf2"
],
"x-hs-incoming-domain": [
"
hubapi.com"
],
"Authorization": [
"Bearer CND3rJ******"
],
"cf-visitor": [
"{\"scheme\":\"https\"}"
],
"X-HS-Internal-Request": [
"1"
],
"cf-connecting-ip": [
"122.176.33.160"
],
"Content-Length": [
"1609"
],
"X-Real-IP": [
"122.176.33.160"
],
"Content-Type": [
"application/json"
],
"Cookie": [
"__cf_bm=q6VRI4ik5hsFXde4sFN5Y0HlUNN.h_hgQOs0vw.RNLs-1754550456-1.0.1.1-bEeV9NpkBCzILRSvRe1B9uQzx6F79a.JcpEEotAf1ym2zmgNtGzKlPdC98lIsuRC9X1hrv_xDFBnd_crmtfhqRHD4a8tFtuZDGzdRTxtUnI"
],
"cdn-loop": [
"cloudflare; loops=1; subreqs=1"
],
"cf-worker": [
"
hubapi.com"
],
"CF-Ray": [
"96b4f3fc8548919a-PDX"
],
"Accept": [
"*/*"
],
"X-Forwarded-Proto": [
"https"
],
"Connection": [
"close"
],
"X-Request-Start": [
"1754550614.861"
],
"X-HS-Internal-User-Request": [
"0"
],
"Host": [
"
api-na1.hubapi.com"
],
"X-HS-User-Request": [
"0"
],
"X-Forwarded-Port": [
"443"
],
"X-Amzn-Trace-Id": [
"Root=1-68945156-28572ac278788cb66230e418"
],
"X-Forwarded-For": [
"122.176.33.160, 172.68.175.21, 122.176.33.160, 122.176.33.160"
],
"X-HubSpot-Cross-Hublet-Request": [
"1"
],
"cf-ew-via": [
"15"
],
"X-Scheme": [
"https"
],
"X-HubSpot-Correlation-Id": [
"a4c396c3-7779-4c5d-8c8e-0ee39bbd30a5"
]
}
body:{
"enabled": true,
"name": "Send SMS/WhatsApp via SendMetrix",
"description": "Send SMS or WhatsApp messages via SendMetrix gateway from HubSpot workflows.",
"actions": [
{
"id": "send_sms_whatsapp",
"name": "Send SMS/WhatsApp Message",
"type": "STANDARD",
"labels": {
"en": "Send SMS/WhatsApp"
},
"inputFields": [
{
"type": "enumeration",
"fieldType": "select",
"name": "channel",
"label": "Message Channel",
"description": "Choose SMS or WhatsApp",
"options": [
{ "label": "SMS", "value": "sms" },
{ "label": "WhatsApp", "value": "whatsapp" }
],
"required": true,
"groupName": "message"
},
{
"type": "string",
"fieldType": "text",
"name": "message",
"label": "Message Content",
"description": "Use tokens, e.g. {{ contact.firstname }}",
"required": true,
"groupName": "message"
},
{
"type": "string",
"fieldType": "text",
"name": "phone_number",
"label": "Phone Number",
"description": "Contact's phone number or contact property with phone.",
"required": true,
"groupName": "message"
}
],
"outputFields": [
{
"type": "string",
"fieldType": "text",
"name": "status",
"label": "Send Status"
}
]
}
],
"callbackUrl": "
https://hubspotapi.onrender.com/workflow/trigger"
}
Response:
{"status":"error","message":"Authentication credentials not found. This API supports OAuth 2.0 authentication and you can find more details at
https://developers.hubspot.com/docs/methods/auth/oauth-overview","correlationId":"a4c396c3-7779-4c5d-8c8e-0ee39bbd30a5","category":"INVALID_AUTHENTICATION"}