Hubspot custom workflow action error on external api call

Hi all,

I am trying to create a custom action for workflow for whoever uses my application. I want to make an external API call to get data based on the `portalId` of the account.
I have drop down a drop down select which will show options based on the data that is returned from the external API call.
But for some reason I am getting error could not load due to a 3rd-party API failure.

Here is a sample of code that I am using

{
 "actionUrl": "https://example.com/hubspot",
 "published" : true,
 "inputFields": [
 {
 "typeDefinition": {
 "name": "widgetName",
 "type": "string",
 "fieldType": "text"
 },
 "supportedValueTypes": ["STATIC_VALUE"],
 "isRequired": true
 },
 {
 "typeDefinition": {
 "name": "widgetColor",
 "type": "enumeration",
 "fieldType": "select",
 "options": [
 { "value": "red", "description": "red", "label": "Red" },
 { "value": "blue", "description": "blue", "label": "Blue" },
 { "value": "green", "description": "green", "label": "Green" }
 ]
 },
 "supportedValueTypes": ["STATIC_VALUE"]
 },
 {
 "typeDefinition": {
 "name": "widgetSize",
 "type": "enumeration",
 "fieldType": "select",
 "optionsUrl": "https://api.example.com/v1/widget-sizes"
 },
 "supportedValueTypes": ["STATIC_VALUE"]
 },
 {
 "typeDefinition": {
 "name": "widgetCost",
 "type": "number",
 "fieldType": "number"
 },
 "supportedValueTypes": ["OBJECT_PROPERTY"]
 }
 ],
 "inputFieldDependencies": [
 {
 "dependencyType": "SINGLE_FIELD",
 "controllingFieldName": "widgetColor",
 "dependentFieldNames": ["widgetSize"]
 },
 {
 "dependencyType": "CONDITIONAL_SINGLE_FIELD",
 "controllingFieldName": "widgetColor",
 "controllingFieldValue": "red",
 "dependentFieldNames": ["widgetCost"]
 }
 ],
 "labels": {
 "en": {
 "actionName": "Create Widget - Example 3",
 "actionCardContent": "Create widget {{widgetName}}",
 "inputFieldLabels": {
 "widgetName": "Widget Name",
 "widgetColor": "Widget Color",
 "widgetSize": "Widget Size",
 "widgetCost": "Widget Cost"
 }
 }
 },
 "objectTypes": ["CONTACT", "DEAL"],
 "functions": [
 {
 "functionType": "PRE_FETCH_OPTIONS",
 "id": "widgetSize",
 "functionSource": "exports.main = function(event, callback) { return callback(transformRequest(event)); }\nfunction transformRequest(request) { return { webhookUrl: request.webhookUrl + '?color=' + request.fields.widgetColor.value, body: JSON.stringify(request.fields), httpMethod: 'GET' }; }"
 }
 ]
}

And this is the error which is being shown in the workflow

Hi, @neer :waving_hand: Thanks for your question. I’d like to invite some of our community members to the conversation — hey @zach_threadint @MatthiasKunz do you have any recent experience with similar errors to what @neer shared?

I have some basic troubleshooting steps:

  • Check that the external API (https://api.example.com/v1/widget-sizes) is operational and accessible. You can use a tool like Postman to test the endpoint directly
  • Ensure the API’s response matches the expected format for HubSpot, like [{ “value”: “size1”, “label”: “Size 1” }]
  • Double-check your custom function that modifies the request to ensure it constructs a valid API URL and correctly passes all necessary parameters. Make sure the method (GET or POST) matches the requirements
  • Confirm there are no network issues or CORS policies preventing HubSpot from accessing the API

Best,

Jaycee

Hi @neer @Jaycee_Lewis :waving_hand:

I’m getting the same error message when trying to implement the only full example using the “PRE_FETCH_OPTIONS” function type outlined in the HubSpot documentation.

(Example #3, right down the bottom of the doc)

. The only meaningful change I made to the documented example was to point to my ‘actionUrl’ and ‘optionsUrl’ endpoints:

POST: /automation/v4/actions/:APP_ID

{
 "actionUrl": "https://webhook.site/12345-abcde",
 "published": true,
 "inputFields": [
 {
 "typeDefinition": {
 "name": "widgetName",
 "type": "string",
 "fieldType": "text"
 },
 "supportedValueTypes": ["STATIC_VALUE"],
 "isRequired": true
 },
 {
 "typeDefinition": {
 "name": "widgetColor",
 "type": "enumeration",
 "fieldType": "select",
 "options": [
 { "value": "red", "description": "red", "label": "Red" },
 { "value": "blue", "description": "blue", "label": "Blue" },
 { "value": "green", "description": "green", "label": "Green" }
 ]
 },
 "supportedValueTypes": ["STATIC_VALUE"]
 },
 {
 "typeDefinition": {
 "name": "widgetSize",
 "type": "enumeration",
 "fieldType": "select",
 "optionsUrl": "https://webhook.site/abcde-12345"
 },
 "supportedValueTypes": ["STATIC_VALUE"]
 },
 {
 "typeDefinition": {
 "name": "widgetCost",
 "type": "number",
 "fieldType": "number"
 },
 "supportedValueTypes": ["OBJECT_PROPERTY"]
 }
 ],
 "inputFieldDependencies": [
 {
 "dependencyType": "SINGLE_FIELD",
 "controllingFieldName": "widgetColor",
 "dependentFieldNames": ["widgetSize"]
 },
 {
 "dependencyType": "CONDITIONAL_SINGLE_FIELD",
 "controllingFieldName": "widgetColor",
 "controllingFieldValue": "red",
 "dependentFieldNames": ["widgetCost"]
 }
 ],
 "labels": {
 "en": {
 "actionName": "Create Widget",
 "actionCardContent": "Create widget {{widgetName}}",
 "inputFieldLabels": {
 "widgetName": "Widget Name",
 "widgetColor": "Widget Color",
 "widgetSize": "Widget Size",
 "widgetCost": "Widget Cost"
 }
 }
 },
 "objectTypes": ["CONTACT", "DEAL"],
 "functions": [
 {
 "functionType": "PRE_FETCH_OPTIONS",
 "id": "widgetSize",
 "functionSource": "exports.main = function(event, callback) { return callback(transformRequest(event)); }\nfunction transformRequest(request) { return { webhookUrl: request.webhookUrl + '?color=' + request.fields.widgetColor.value, body: JSON.stringify(request.fields), httpMethod: 'GET' }; }"
 }
 ]
}

That request succeeds in creating the custom workflow action. Then, when I try to interact with the workflow action in HubSpot UI, I get the same error message experienced by @neer and no request is received by my example endpoint. There could be something funny going on, or at least the example in the documentation needs to be reviewed (I suspect something wrong with the example ‘functionSource’, but I could be wrong).

I hope this proves helpful. Please let me know if you have any follow-up questions.

How your passing portal id in external api. Can you show the code snippet. I believe you added in

“functionType”: “POST_FETCH_OPTIONS”,

“id”:“yourinputfieldid”,

“functionSource”: “your code”

Adding to what @Jaycee_Lewis is writing above, if you have the option to observe the traffic either on your code or on the external API’s side, that might give you some more details on that error message you are getting here. As it is, it’s hard to tell what might be going wrong since we do not know what you are calling, or what the exact error message from the other endpoint is. If this is not an option, you would have to resort to the steps above to narrow things down a little.

I also used Example 3 from hubspot custom workflow action documentation.

Just changed the `optionsURL` and `actionURL`.
I am able to hit my ‘actionURL’ but don’t know why ‘optionsUrl’ is not getting hit and I am getting error while populating the fields

Hi @zach_threadint @Jaycee_Lewis
Is there any work around for this?
My “actionUrl” is working fine
but “optionsUrl” is not.
Show the functionType be “PRE_FETCH_OPTIONS” or is there any other things I am missing ?

@neer @zach_threadint @Jaycee_Lewis There is any solution for above problem because I also faced same problem for my action. Please let me know if there is any solution for it. Thanks.

I’m also encountering this issue now. For some reason, the fields and inputFields are empty.
I have 2 identical apps with same custom actions and it’s only happening to my test app.

@nickiearchuaI think the issue is related to your local environment because the local project URL can’t be called by HubSpot to fetch options. Can you please tell me which language you use?

@KPadhiyar it’s pointing to the correct URL.
This is the sampe payload I’m getting in my test app

{ "origin": { "portalId": 123123123, "actionDefinitionId": 123123, "actionDefinitionVersion": 1, "actionExecutionIndexIdentifier": null, "extensionDefinitionId": 123123, "extensionDefinitionVersionId": 1}, "inputFieldName": "myField", "fetchOptions": { "q": ""}, "objectTypeId": "0-1", "fields": {}, "userId": 123123, "inputFields": {}, "extensionDefinitionId": 123123, "extensionsDefinitionVersion": 1, "portalId": 123123123}

But when I test the other app which is completely identical, the fields and inputFields have values in it.

@nickiearchua Do you get a HubSpot call for fetching options? Because when I worked on this, I had a problem with my project’s local URL, which couldn’t be accessed by HubSpot.

@KPadhiyar yes I’m getting HubSpot call from HubSpot in my optionsUrl.
We probably have different issue.