APIs & Integrations

ABlue2
Member

Custom Workflow Action - serverless function

Hi there, 

 

I'm currently busy with custom workflow actions, as part of this I'm using serverless functions.

So I have a two-part question: 

1) Is it possible to get the creator of the workflow in the serverless function in the PRE_ACTION_EXECUTION function. 

2) Is it possible to get the WorkflowID in the PRE_FETCH_OPTIONS function. 

 

1st scenario: PRE_ACTION_EXECUTION

 

The properties available in the request object:

{

 "callbackId": "xx-xxxxxxx-xxxxxxxxxxx-xx-x",

 "origin": {

 "portalId": xxxxxxx,

 "actionDefinitionId": xxxxxxx,

 "actionDefinitionVersion": 1,

 "extensionDefinitionId": xxxxxxx,

 "extensionDefinitionVersionId": 1

 },

 "context": {

 "source": "WORKFLOWS",

 "workflowId": xxxxxxx

 },

 "object": {

 "objectId": xxxxxxx,

 "propertyValues": {

 "hs_object_id": {

 "name": "hs_object_id",

 "value": "xxxxxxx",

 "timestamp": 1600772341152,

 "source": "CALCULATED",

 "sourceVid": [],

 "sourceMetadata": "xxxxxxxxxxxxxxxxxxxxxxx="

 },

 "email": {

 "name": "email",

 "value": "xxxxxxxxx@xxxxxx.com",

 "timestamp": 1600772341152,

 "sourceId": "xxxxxx",

 "source": "CONTACTS",

 "sourceVid": [],

 "requestId": "xxxxxxxxxxxxxxxxxxxxx"

 }

 },

 "properties": {

 "hs_object_id": "xxxx",

 "email": "xxxxxxxx@xxxxxxx.com"

 },

 "objectType": "CONTACT"

 },

 "fields": {

 "inputfield1": "xxxxxxxxxxx",

 "inputfield2": "xxxxxxxxxxx"

 },

 "inputFields": {

 "inputfield1": "xxxxxxxxxxx",

 "inputfield2": "xxxxxxxxxxx"

 },

 "webhookUrl": "https://myurl.com/api/myfunction"

}

 

It's important to my functionality to be able to identify the creator of the workflow and pass in the user_id. However, as you can see from the data above I cannot seem to find a way to get there here.

 

I'm aware of the solution someone else posted, where you query the workflows and match it using the flowId. However, if this is done in this manner it would need to be repeated every single time this automation was called. Whereas if I could get that value here (the user_id of the creator of the workflow) it would only be set once and be much more efficient.

 

2nd scenario: PRE_FETCH_OPTIONS

 

To try to sort this, I decided to attempt this from a different angle. Using the PRE_FETCH_OPTIONS retrieve a list of values from my system by passing in the portalId and the workflowId. But apparently the WorkflowId is not available in the PRE_FETCH_OPTIONS context. 

 

the properties available in the PRE_FETCH_OPTIONS request object:

{

 "origin": {

 "portalId": xxxxxx,

 "actionDefinitionId": xxxxxx,

 "actionDefinitionVersion": 1,

 "extensionDefinitionId": xxxxxx,

 "extensionDefinitionVersionId": 1

 },

 "fetchOptions": {},

 "fields": {},

 "portalId": xxxxxx,

 "extensionDefinitionId": xxxxx,

 "extensionsDefinitionVersion": 1,

 "inputFields": {},

 "webhookUrl": "https://myurl.com/api/getitems"

}

 

The serverless function doing the work:

 "functions": [

 {

 "functionType": "PRE_FETCH_OPTIONS",

 "id": "myselectlist",

 "functionSource": "exports.main = function(event, callback) { return callback(transformRequest(event)); }\nfunction transformRequest(request) { return { webhookUrl: 'https://myurl.com/api/getitems?portalId=' + request.origin.portalId + '&workflowId=' + request.context.workflowId, httpMethod: 'GET' }; }"

 }

 ]

The underlined part which will fail. Is there another way to retrieve this value here? or the user_id of the creator of the workflow? 

 

Any help would be greatly appreciated, thank you. 

 

 

 

 

 

3 Replies 3
PlyWood
Participant

Custom Workflow Action - serverless function

@ABlue2did you have any luck accessing any additional information in the PRE_FETCH_OPTIONS function or come up with a clever workaround?

ABlue2
Member

Custom Workflow Action - serverless function

Hi @dennisedson,

 

Yes, still working on it.
Unfortunately haven't thought of anything yet. I was hoping there was some part of the documentation I've been missing or a simple answer. If I could just access the WorkflowId or UserId in the PRE_FETCH_OPTIONS function I would be able to sort everything.
Any assistance would be greatly appreciated.

dennisedson
HubSpot Product Team
HubSpot Product Team

Custom Workflow Action - serverless function

Hey @ABlue2 

Are you still working on this?  @lynton , do you have any ideas?

0 Upvotes