Hello @Jaycee_Lewis
Yes , I have created the workflow action as per he custom workflow action guide.
Below is the code -
// server.js
const express = require(‘express’);
const https = require(‘https’);
const fs = require(‘fs’);
const customActionHandler = require(‘./actionHandler’);
const bodyParser = require(‘body-parser’);
const axios = require(‘axios’);
require(‘dotenv’).config();
const options = {
key: fs.readFileSync(‘./server.key’),
cert: fs.readFileSync(‘./server.cert’)
};
// Create an Express app
const app = express();
const hubspot = require(‘@hubspot/api-client’);
const hubspotClient = new hubspot.Client({“developerApiKey”:process.env.HUBSPOT_API_KEY});
const appId = process.env.APP_ID;
const limit = undefined;
const after = undefined;
const archived = false;
app.use(bodyParser.urlencoded({
extended: true
}));
app.get(‘/generate_refresh_token’, (req, res) => {
// Generate refresh and initial access token.
let code = req.query.code;
if(code != " ")
{
console.log(‘Code’+code);
let url = “https://api.hubapi.com/oauth/v1/token”;
let postData = {
grant_type:“authorization_code”,
client_id:process.env.CLIENT_ID,
client_secret:process.env.CLIENT_SECRTET,
redirect_uri:“https://localhost:3000/generate_refresh_token”,
code: code
};
axios.post(url, postData, {
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded’,
}})
.then(response => {
// Handle the API response
console.log(response);
//return response;
res.redirect(‘https://localhost:3000/create_custom_action’);
})
.catch(error => {
// Handle errors
console.error(error);
});
}
});
app.get(‘/create_custom_action’, (req, res) => {
async function call_api(){
const ExtensionActionDefinitionInput = {
actionUrl: “https://localhost:3000/create_custom_action”,
inputFields: [
{
“typeDefinition”: {
“name”: “widgetName”,
“type”: “string”,
“fieldType”: “text”
},
“supportedValueTypes”: [“STATIC_VALUE”],
“isRequired”: true
},
{
“typeDefinition”: {
“name”: “widgetColor”,
“type”: “enumeration”,
“fieldType”: “select”,
“options”: [
{ “value”: “red”, “label”: “Red” },
{ “value”: “blue”, “label”: “Blue” },
{ “value”: “green”, “label”: “Green” }
]
},
“supportedValueTypes”: [“STATIC_VALUE”]
},
{
“typeDefinition”: {
“name”: “widgetOwner”,
“type”: “enumeration”,
“referencedObjectType”: “OWNER”
},
“supportedValueTypes”: [“STATIC_VALUE”]
},
{
“typeDefinition”: {
“name”: “widgetQuantity”,
“type”: “number”
},
“supportedValueTypes”: [“OBJECT_PROPERTY”]
}
],
labels: {
“en”: {
“actionName”: “Create Widget - Example 1”,
“actionDescription”: “This action will create a new widget in our system. So cool!”,
“actionCardContent”: “Create widget {{widgetName}}”,
“inputFieldLabels”: {
“widgetName”: “Widget Name”,
“widgetColor”: “Widget Color”,
“widgetOwner”: “Widget Owner”,
“widgetQuantity”: “Widget Quantity”
},
“inputFieldDescriptions”: {
“widgetName”: “Enter the full widget name. I support <a href=\”[https://hubspot.com\](https://hubspot.com)“>links</a> too.”,
“widgetColor”: “This is the color that will be used to paint the widget.”
}
}
},
objectTypes: [“CONTACT”, “DEAL”]
};
var output_response = {
error : “Something went wrong”
}
try {
const apiResponse = await hubspotClient.automation.actions.definitionsApi.create(appId, ExtensionActionDefinitionInput);
//console.log(JSON.stringify(apiResponse, null, 2));
output_response = JSON.stringify(apiResponse, null, 2);
} catch (e) {
e.message === ‘HTTP request failed’
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
output_response = JSON.stringify(e.response, null, 2);
}
res.json(output_response);
}
call_api();
});
const server = https.createServer(options, app);
const port = 3000; // or any other port you prefer
server.listen(port, () => {
console.log(`Server running on https://localhost:${port}`);
});
Thanks & Regards,
Richa Mandhan