Issue with POST_FETCH_OPTIONS Workflow API

Hi Team,

We are facing an issue with the Workflow API. Specifically, the POST_FETCH_OPTIONS is not passing the selected campus input field value, and the options URL in the cascade dropdown list is not being updated.

We are using the following code to retrieve the first dropdown’s selected value and pass it to the second dropdown’s options URL. However, it’s no longer working as expected:

const campusid = responseData.data.fields.campusInput.fieldValue.value;

Here is the structure of the API configuration:

{
“actionUrl”: “https://test.com/integration/hubspot/webhook”,
“published”: true,
“objectTypes”: [“CONTACT”, “Companies”, “Deals”, “Tickets”, “Quotes”, “Products”, “Invoices”, “Communications”],
“inputFields”: [
{
“typeDefinition”: {
“name”: “messageInput”,
“type”: “string”,
“fieldType”: “text”
},
“supportedValueTypes”: [“STATIC_VALUE”],
“isRequired”: true
},
{
“typeDefinition”: {
“name”: “campusInput”,
“type”: “enumeration”,
“fieldType”: “select”,
“optionsUrl”: “https://test.com/integration/hubspot/orgunit/campus-selection”
},
“supportedValueTypes”: [“STATIC_VALUE”]
},
{
“typeDefinition”: {
“name”: “groupInput”,
“type”: “enumeration”,
“fieldType”: “select”,
“optionsUrl”: “https://test.com/integration/hubspot/orgunit/campus-selection”
},
“supportedValueTypes”: [“STATIC_VALUE”]
}
],
“objectRequestOptions”: {
“properties”: [“mobilephone”, “email”]
},
“labels”: {
“en”: {
“inputFieldLabels”: {
“messageInput”: “Message”,
“groupInput”: “Group”,
“campusInput”: “Campus”
},
“actionName”: “Send Message V1_08052024”,
“actionDescription”: “Send Message V1_08052024”,
“appDisplayName”: “Powered By Text”,
“actionCardContent”: “Send through Powered By Text”
}
},
“functions”: [
{
“functionType”: “POST_ACTION_EXECUTION”,
“functionSource”: “exports.main = (event, callback) => { callback({ outputFields: { myOutput: \“example output value\” } }); }”
},
{
“functionType”: “POST_FETCH_OPTIONS”,
“id”: “campusInput”,
“functionSource”: “const axios = require(‘axios’); exports.main = async (event, callback) => { try { const responseData = JSON.parse(event.responseBody); const portalId = responseData.data.origin.portalId; const campusurl='https://test.com/integration/hubspot/orgunit/'+portalId; const response = await axios.get(campusurl); const data = response.data.data; const options = data.map(item => ({\“label\”: item.name, \“value\”: item.id})); callback({ \“options\”: options }); } catch (error) { console.error(‘Error fetching options:’, error); callback({ \“options\”: [] }); } }”
},
{
“functionType”: “POST_FETCH_OPTIONS”,
“id”: “groupInput”,
“functionSource”: “const axios = require(‘axios’); exports.main = async (event, callback) => { try { const responseData = JSON.parse(event.responseBody); const portalId = responseData.data.origin.portalId; const campusid=responseData.data.fields.campusInput.fieldValue.value; const groupurl='https://test.com/integration/hubspot/orgunit/'+ campusid + ‘/group/’+ portalId; await axios.post(‘https://webhook.site/7e966653-3fe1-4bed-8542-706abfb86bb0’, { groupUrl: groupurl }); const response = await axios.get(groupurl); const data = response.data.data; const options = data.map(item => ({\“label\”: item.name, \“value\”: item.id})); callback({ \“options\”: options }); } catch (error) { console.error(‘Error fetching options:’, error); callback({ \“options\”: [] }); } }”
}
]
}

Could you please help investigate and advise on potential solutions to resolve this issue?

Thank you.

Best regards,
Suresh


@SBabuS wrote:

Hi Team,

We are facing an issue with the Workflow API. Specifically, the POST_FETCH_OPTIONS is not passing the selected campus input field value, and the options URL in the cascade dropdown list is not being updated.

We are using the following code to retrieve the first dropdown’s selected value and pass it to the second dropdown’s options URL of picsart. However, it’s no longer working as expected:

const campusid = responseData.data.fields.campusInput.fieldValue.value;

Here is the structure of the API configuration:

{
“actionUrl”: “https://test.com/integration/hubspot/webhook”,
“published”: true,
“objectTypes”: [“CONTACT”, “Companies”, “Deals”, “Tickets”, “Quotes”, “Products”, “Invoices”, “Communications”],
“inputFields”: [
{
“typeDefinition”: {
“name”: “messageInput”,
“type”: “string”,
“fieldType”: “text”
},
“supportedValueTypes”: [“STATIC_VALUE”],
“isRequired”: true
},
{
“typeDefinition”: {
“name”: “campusInput”,
“type”: “enumeration”,
“fieldType”: “select”,
“optionsUrl”: “https://test.com/integration/hubspot/orgunit/campus-selection”
},
“supportedValueTypes”: [“STATIC_VALUE”]
},
{
“typeDefinition”: {
“name”: “groupInput”,
“type”: “enumeration”,
“fieldType”: “select”,
“optionsUrl”: “https://test.com/integration/hubspot/orgunit/campus-selection”
},
“supportedValueTypes”: [“STATIC_VALUE”]
}
],
“objectRequestOptions”: {
“properties”: [“mobilephone”, “email”]
},
“labels”: {
“en”: {
“inputFieldLabels”: {
“messageInput”: “Message”,
“groupInput”: “Group”,
“campusInput”: “Campus”
},
“actionName”: “Send Message V1_08052024”,
“actionDescription”: “Send Message V1_08052024”,
“appDisplayName”: “Powered By Text”,
“actionCardContent”: “Send through Powered By Text”
}
},
“functions”: [
{
“functionType”: “POST_ACTION_EXECUTION”,
“functionSource”: “exports.main = (event, callback) => { callback({ outputFields: { myOutput: \“example output value\” } }); }”
},
{
“functionType”: “POST_FETCH_OPTIONS”,
“id”: “campusInput”,
“functionSource”: “const axios = require(‘axios’); exports.main = async (event, callback) => { try { const responseData = JSON.parse(event.responseBody); const portalId = responseData.data.origin.portalId; const campusurl='https://test.com/integration/hubspot/orgunit/'+portalId; const response = await axios.get(campusurl); const data = response.data.data; const options = data.map(item => ({\“label\”: item.name, \“value\”: item.id})); callback({ \“options\”: options }); } catch (error) { console.error(‘Error fetching options:’, error); callback({ \“options\”: [] }); } }”
},
{
“functionType”: “POST_FETCH_OPTIONS”,
“id”: “groupInput”,
“functionSource”: “const axios = require(‘axios’); exports.main = async (event, callback) => { try { const responseData = JSON.parse(event.responseBody); const portalId = responseData.data.origin.portalId; const campusid=responseData.data.fields.campusInput.fieldValue.value; const groupurl='https://test.com/integration/hubspot/orgunit/'+ campusid + ‘/group/’+ portalId; await axios.post(‘https://webhook.site/7e966653-3fe1-4bed-8542-706abfb86bb0’, { groupUrl: groupurl }); const response = await axios.get(groupurl); const data = response.data.data; const options = data.map(item => ({\“label\”: item.name, \“value\”: item.id})); callback({ \“options\”: options }); } catch (error) { console.error(‘Error fetching options:’, error); callback({ \“options\”: [] }); } }”
}
]
}

Could you please help investigate and advise on potential solutions to resolve this issue?

Thank you.

Best regards,
Suresh


It appears that the POST_FETCH_OPTIONS function for groupInput is not receiving the selected value from campusInput. In HubSpot’s custom workflow actions, input fields can be defined to fetch external data dynamically using the optionsUrl parameter. When a user interacts with the workflow, the system sends a payload to the specified optionsUrl, which includes details about the current state of input fields. To ensure that the groupInput field receives the selected value from campusInput, you should verify that the payload sent to the optionsUrl of groupInput includes the current value of campusInput. This can be achieved by properly configuring the input fields and ensuring that the optionsUrl endpoints are correctly processing the incoming payload to return the appropriate options based on the selected campus. For detailed guidance on setting up input fields and handling dynamic data fetching, you can refer to HubSpot’s documentation on custom workflow actions. Accounts Dashboard | HubSpot?

Hey, @SBabuS :waving_hand: I took a look at your queisotn and had Gemini look for one thing we might be missing. Here’s a suggestion gor anyone who comes upon this post.

I’ll add the corrected `functionSource` for the `groupInput` field below. This code should successfully get the `campusid` and fetch the dependent options.

While the fix above works, a more standard pattern is to have your `optionsUrl` for `groupInput` point directly to the final endpoint (e.g., https://test.com/integration/hubspot/orgunit/group-selection).

When you do this, HubSpot automatically sends the `requestData` payload (with allFields) to that URL. Your endpoint can then receive it, filter the list, and return the correct options directly, often removing the need for a `POST_FETCH_OPTIONS` function entirely.

Best,

Jaycee

{
 "functionType": "POST_FETCH_OPTIONS",
 "id": "groupInput",
 "functionSource": "const axios = require('axios');
 exports.main = async (event, callback) => {
 try {
 // 1. Parse the REQUEST payload, not the response body
 const requestData = JSON.parse(event.payload);

 // 2. Get the campus ID from the 'allFields' object
 const campusid = requestData.allFields.campusInput;

 // 3. Get the portalId from the payload
 const portalId = requestData.origin.portalId;

 // 4. Check if campusid is present before making the call
 if (!campusid) {
 console.log('No campus ID selected, returning empty options.');
 callback({ \"options\": [] });
 return;
 }

 // 5. Build your dynamic URL and make the request
 const groupurl = `https://test.com/integration/hubspot/orgunit/${campusid}/group/${portalId}`;

 // This debug webhook is a great idea
 await axios.post('https://webhook.site/7e966653-3fe1-4bed-8542-706abfb86bb0', { 
 groupUrl: groupurl, 
 campusIdFromPayload: campusid 
 });

 const response = await axios.get(groupurl);
 const data = response.data.data;
 const options = data.map(item => ({ \"label\": item.name, \"value\": item.id }));

 callback({ \"options\": options });

 } catch (error) {
 console.error('Error fetching dynamic options:', error);
 callback({ \"options\": [] });
 }
 }"
}