I have two apps I created for our customers to integrate hubspot with our platform. Each relies on using an external API call to pull a list of possible options into a dropdown, as per this documentation on 3rd party post fetch options .
The field we are tyring to create uses the following definitions:
"inputFields": [
{
"typeDefinition": {
"name": "endpoint_id",
"type": "enumeration",
"schema": {
"format": null,
"type": "STRING"
},
"fieldType": "select",
"options": [],
"optionsUrl": "https://testapi.test/api/v1/hubspot/drips",
"referencedObjectType": null,
"externalOptions": false,
"externalOptionsReferenceType": null
},
"supportedValueTypes": [
"STATIC_VALUE"
],
"isRequired": false,
"includeEmptyIfValueAbsent": false,
"automationFieldType": null,
"allowedObjectTypes": null
}
]
And the function that powers it is:
"functions": [
{
"functionType": "POST_FETCH_OPTIONS",
"id": "endpoint_id",
"functionSource": "exports.main = (response, callback) => {\n return callback(transformResponse(response));\n};\n\nfunction transformResponse(response) {\n let body = JSON.parse(response.responseBody);\n\n // External value fields in multi value fields in custom actions v1 were\n // migrated to have a key like v1FieldKey__hs1 in custom actions v2\n let fieldKey = response.fieldKey.replace(/__hs[0-9]+/, '');\n\n if (!body.options || !(fieldKey in body.options)) {\n return { options: [] };\n }\n\n let options = [];\n for (const label in body.options[fieldKey]) {\n options.push({\n label,\n value: body.options[fieldKey][label]\n });\n }\n\n return { options };\n}\n"
}
]
Our reponse code back from our API endpoint is formatted as follows:
{
"options": {
"endpoint_id": {
"Option 1": "CkFzzbbyLTGVSLbNRqGxCtAJVJBBsF",
"Option 2": "tDwoxoUgnTyIJRrNVmeyLzRmCNzqPU"
}
}
}
Here’s the sad thing. Both app A and app B have the exact same configurations. App A works currently. App B failes every time with the error “options could not load due to a 3rd-party API failure. To load please refresh the page.”. Any app I create by redownloading the config file and recreating the app (i.e. app c, d, e) also fails as such. I cannot figure out why the first app even works now.
I’ve tried modifiying the API endpoint to send back the data exactly as the API document suggestions:
{
"options": [
{
"label": "Big Widget",
"description": "Big Widget",
"value": "10"
},
{
"label": "Small Widget",
"description": "Small Widget",
"value": "1"
}
]
}
And used the following post fetch function as well:
exports.main = function(event, callback) { return callback(transformRequest(event)); }
function transformRequest(request) { return { webhookUrl: request.webhookUrl, body: JSON.stringify(request), httpMethod: 'POST' }; }
And yet still the field returns the same error. How can I effectively create a dynamic drop down ufor the workfloe extension?