• Créditos da HubSpot: Desbloqueie ferramentas poderosas para o crescimento

    Dúvidas?

APIs & Integrations

KPadhiyar
Participante

How to create workflow with Custom workflow action?

resolver

I want to create a workflow in HubSpot using PHP and attach a custom workflow action during its creation. Can anyone guide me on how to do this? I’ve checked the documentation but couldn’t find anything.

Thanks...

4 Solução aceitas
Josh
Solução
Especialista reconhecido(a) | Parceiro Diamante
Especialista reconhecido(a) | Parceiro Diamante

How to create workflow with Custom workflow action?

resolver

Hi @KPadhiyar,

 

Here's a link to the documentation: https://developers.hubspot.com/beta-docs/reference/api/automation/custom-code-actions

 

Josh 


Did this post help solve your problem? If so, please mark it as a solution.

Josh Curcio

HubSpot support and inbound marketing for OEMs, contract manufacturers, and industrial suppliers.
HubSpot Diamond Partner & HubSpot Certified Trainer

Exibir solução no post original

0 Avaliação positiva
SteveHTM
Solução
Conselheiro(a) de destaque

How to create workflow with Custom workflow action?

resolver

@KPadhiyar - building on the reponse from @Josh , there is an automation API that support progreammtic creation/update to any workflow.

https://developers.hubspot.com/beta-docs/reference/api/automation/create-manage-workflows

As far as I have been able to determine, these APIs can display the details of custom code actions in any query for a given workflow, but cannot suppprt the creation/update of code sections in that workflow step.

 

Bottom line, this maybe needs a HubSpot update to round out the implementation.

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature

Exibir solução no post original

0 Avaliação positiva
MichaelMa
Solução
Top colaborador(a)

How to create workflow with Custom workflow action?

resolver

@KPadhiyar What is your action expected to do? It seems like it's missing field data. That's probably why you're getting an error.

 

Eg,

Here is an action that updates the Deal Name to include the company name. As you can see the fields property has more properties showing what it's going to do. Sorry, it's in JSON format.

        {
            "actionId": "2",
            "actionTypeVersion": 0,
            "actionTypeId": "0-5",
            "fields": {
                "property_name": "dealname",
                "value": {
                    "staticValue": "{{ enrolled_object.dealname }} - {{ fetched_objects.fetched_object_180997189.name }}",
                    "type": "STATIC_VALUE"
                }
            },
            "type": "SINGLE_CONNECTION"
        }

 

Here is one that delays for 5 minutes:

 

        {
            "actionId": "3",
            "actionTypeVersion": 0,
            "actionTypeId": "0-1",
            "fields": {
                "delta": "5",
                "time_unit": "MINUTES"
            },
            "type": "SINGLE_CONNECTION"
        }

 

Custom Code Actions (using default Hubspot code):

        {
            "actionId": "4",
            "secretNames": [],
            "sourceCode": "exports.main = async (event, callback) => {\n  /*****\n    Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.\n  *****/\n  const email = event.inputFields['email'];\n  /*****\n    Use the callback function to output data that can be used in later actions in your workflow.\n  *****/\n  callback({\n    outputFields: {\n      email: email\n    }\n  });\n}",
            "runtime": "NODE20X",
            "inputFields": [],
            "outputFields": [],
            "type": "CUSTOM_CODE"
        }

 

I'm not sure I can extrapolate what you intend with just 'fieldName' => 'fieldValue'. Are you trying to set the value of fieldName on the object? If so, you are missing additional properties.

 

The easiest way to get the structure is to make a similar workflow in Hubspot and do a GET request on it. You can then see how it's built. Much easier than trying to figure out the documentation.

Exibir solução no post original

0 Avaliação positiva
MichaelMa
Solução
Top colaborador(a)

How to create workflow with Custom workflow action?

resolver

If you already have the workflow created, easiest way is to just use a GET on https://api.hubspot.com/automation/v4/flows/YOUR_WORKFLOW_ID to get the workflow data and copy your actions data (or everything if you really wanted).

 

It sounds like you're trying to recreate a Webhook action. The basic structure for a Webhook action is:

 

        {
            "actionId": "5",
            "method": "POST",
            "webhookUrl": "https://endpoint here",
            "queryParams": [],
            "authSettings": {
                "appId": 1234567890,
                "type": "SIGNATURE"
            },
            "type": "WEBHOOK"
        }

 

Unless you mean you want to create a Custom Code Action:

        {
            "actionId": "4",
            "secretNames": [],
            "sourceCode": "exports.main = async (event, callback) => {\n  /*****\n    Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.\n  *****/\n  const email = event.inputFields['email'];\n  /*****\n    Use the callback function to output data that can be used in later actions in your workflow.\n  *****/\n  callback({\n    outputFields: {\n      email: email\n    }\n  });\n}",
            "runtime": "NODE20X",
            "inputFields": [],
            "outputFields": [],
            "type": "CUSTOM_CODE"
        }

 

But it's literally easier to just build the workflow or actions you want in Hubspot, then use a GET request on it and copy the action data.

Exibir solução no post original

0 Avaliação positiva
11 Respostas 11
KPadhiyar
Participante

How to create workflow with Custom workflow action?

resolver

@SteveHTM @Josh 
Also, I've below code and got this error:

$requestBody = [
  'type' => 'CONTACT_FLOW',
  'name' => 'Test WorkFlow',
  'description' => 'Test WorkFlow',
  'canEnrollFromSalesforce' => false,
  'isEnabled' => true,
  'flowType' => 'WORKFLOW',
  'crmObjectCreationStatus' => 'COMPLETE',
  'objectTypeId' => '0-1',
  'startActionId' => 'actionId',
  'enrollmentCriteria' => ['shouldReEnroll' => true, 'type' => 'MANUAL'],
  'objectType' => 'CONTACT',
  'actions' => [
    [
      'type' => 'SINGLE_CONNECTION',
      'actionId' => 'actionId',
      'actionTypeVersion' => 0,
      'actionTypeId' => '0-1',
      'fields' => [
        'fieldName' => 'fieldValue'
      ]
    ]
  ]
];

$response = Http::withToken('access_token')
  ->accept('application/json')
  ->timeout(30)
  ->post('https://api.hubapi.com/automation/v4/flows', $requestBody);

$responseBody = $response->json();

```

[
"status" => "error",
"message" => "internal error",
"correlationId" => "c3bf5626-0afa-4a22-8d7f-4647d7fa0164",
]

```

0 Avaliação positiva
MichaelMa
Solução
Top colaborador(a)

How to create workflow with Custom workflow action?

resolver

@KPadhiyar What is your action expected to do? It seems like it's missing field data. That's probably why you're getting an error.

 

Eg,

Here is an action that updates the Deal Name to include the company name. As you can see the fields property has more properties showing what it's going to do. Sorry, it's in JSON format.

        {
            "actionId": "2",
            "actionTypeVersion": 0,
            "actionTypeId": "0-5",
            "fields": {
                "property_name": "dealname",
                "value": {
                    "staticValue": "{{ enrolled_object.dealname }} - {{ fetched_objects.fetched_object_180997189.name }}",
                    "type": "STATIC_VALUE"
                }
            },
            "type": "SINGLE_CONNECTION"
        }

 

Here is one that delays for 5 minutes:

 

        {
            "actionId": "3",
            "actionTypeVersion": 0,
            "actionTypeId": "0-1",
            "fields": {
                "delta": "5",
                "time_unit": "MINUTES"
            },
            "type": "SINGLE_CONNECTION"
        }

 

Custom Code Actions (using default Hubspot code):

        {
            "actionId": "4",
            "secretNames": [],
            "sourceCode": "exports.main = async (event, callback) => {\n  /*****\n    Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.\n  *****/\n  const email = event.inputFields['email'];\n  /*****\n    Use the callback function to output data that can be used in later actions in your workflow.\n  *****/\n  callback({\n    outputFields: {\n      email: email\n    }\n  });\n}",
            "runtime": "NODE20X",
            "inputFields": [],
            "outputFields": [],
            "type": "CUSTOM_CODE"
        }

 

I'm not sure I can extrapolate what you intend with just 'fieldName' => 'fieldValue'. Are you trying to set the value of fieldName on the object? If so, you are missing additional properties.

 

The easiest way to get the structure is to make a similar workflow in Hubspot and do a GET request on it. You can then see how it's built. Much easier than trying to figure out the documentation.

0 Avaliação positiva
SSun7
Participante

How to create workflow with Custom workflow action?

resolver

Hi @KPadhiyar , may I ask if you have any solution for this? I'm also trying to build workflows with custom workflow action that I've created via custom action endpoint.

0 Avaliação positiva
Victor_Becerra
Gerente da Comunidade
Gerente da Comunidade

How to create workflow with Custom workflow action?

resolver

Hi @SSun7 
Thank you for reaching out to the Community! Just to clarify—are you asking if there’s a way to set up a workflow using the custom action you’ve already built via a custom action endpoint, or are you looking for guidance on how to create the custom action itself?
I'd like to invite some community members who are subject matter experts to join this conversation.
@SteveHTM  @MichaelMa @nickdeckerdevs1 - Would you be able to share any insights on this? Your expertise would be greatly appreciated.
Best,
Victor


loop Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.
Learn More

0 Avaliação positiva
SSun7
Participante

How to create workflow with Custom workflow action?

resolver

I want to create a workflow with a custom workflow action via this endpoint https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/workflows/post-automat.... I've created that custom workflow action to my public app so that every user who installs my public app would be able to see & use that custom workflow action. Currently, what I'm trying to achieve is to also create a demo workflow with that custom workflow action for each user who installs my app so that they can know how to use our workflow action. Our custom workflow action has an action url and options url that would send request to our served backend.

0 Avaliação positiva
MichaelMa
Solução
Top colaborador(a)

How to create workflow with Custom workflow action?

resolver

If you already have the workflow created, easiest way is to just use a GET on https://api.hubspot.com/automation/v4/flows/YOUR_WORKFLOW_ID to get the workflow data and copy your actions data (or everything if you really wanted).

 

It sounds like you're trying to recreate a Webhook action. The basic structure for a Webhook action is:

 

        {
            "actionId": "5",
            "method": "POST",
            "webhookUrl": "https://endpoint here",
            "queryParams": [],
            "authSettings": {
                "appId": 1234567890,
                "type": "SIGNATURE"
            },
            "type": "WEBHOOK"
        }

 

Unless you mean you want to create a Custom Code Action:

        {
            "actionId": "4",
            "secretNames": [],
            "sourceCode": "exports.main = async (event, callback) => {\n  /*****\n    Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.\n  *****/\n  const email = event.inputFields['email'];\n  /*****\n    Use the callback function to output data that can be used in later actions in your workflow.\n  *****/\n  callback({\n    outputFields: {\n      email: email\n    }\n  });\n}",
            "runtime": "NODE20X",
            "inputFields": [],
            "outputFields": [],
            "type": "CUSTOM_CODE"
        }

 

But it's literally easier to just build the workflow or actions you want in Hubspot, then use a GET request on it and copy the action data.

0 Avaliação positiva
SSun7
Participante

How to create workflow with Custom workflow action?

resolver

Hi Michael, 

 

I think the webhook action is the one I need. Could you send me the link to the documentation of webhook action please so I could get a better understanding of it. Thanks.

0 Avaliação positiva
SSun7
Participante

How to create workflow with Custom workflow action?

resolver

Hi Michael, actually the method to build a workflow with custom workflow action then GET it to check its details worked for me. But I still have a few questions regarding it. The actionTypeVersion is 1 and actionTypeId is 1-xxxxx (the xxxxx is the id of my custom workflow action) and I'm wondering if there's any documentation on the choose and formatting of actionTypeVersion and actionTypeId for custom workflow action so that I could better understanding this payload. Thanks.

0 Avaliação positiva
KPadhiyar
Participante

How to create workflow with Custom workflow action?

resolver

@SteveHTM @Josh Thanks for the reply. I can't get it what I need to do. Do you've any example for me so I can do it?
FYI: I'm using PHP language for this.

0 Avaliação positiva
SteveHTM
Solução
Conselheiro(a) de destaque

How to create workflow with Custom workflow action?

resolver

@KPadhiyar - building on the reponse from @Josh , there is an automation API that support progreammtic creation/update to any workflow.

https://developers.hubspot.com/beta-docs/reference/api/automation/create-manage-workflows

As far as I have been able to determine, these APIs can display the details of custom code actions in any query for a given workflow, but cannot suppprt the creation/update of code sections in that workflow step.

 

Bottom line, this maybe needs a HubSpot update to round out the implementation.

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Avaliação positiva
Josh
Solução
Especialista reconhecido(a) | Parceiro Diamante
Especialista reconhecido(a) | Parceiro Diamante

How to create workflow with Custom workflow action?

resolver

Hi @KPadhiyar,

 

Here's a link to the documentation: https://developers.hubspot.com/beta-docs/reference/api/automation/custom-code-actions

 

Josh 


Did this post help solve your problem? If so, please mark it as a solution.

Josh Curcio

HubSpot support and inbound marketing for OEMs, contract manufacturers, and industrial suppliers.
HubSpot Diamond Partner & HubSpot Certified Trainer

0 Avaliação positiva