Skip to main content

Designs from CRM events with HubSpot

When something happens in your CRM, the matching material is ready without anyone asking for it: a webinar is created in HubSpot, and a few minutes later its record holds the link to an announcement post in your corporate design.

A HubSpot workflow calls heycreo's REST API in two custom code steps: one starts the design, the other collects the file and writes its link back to the record.

You need:

  • HubSpot Data Hub Professional or Enterprise, for custom code in workflows.
  • A heycreo API key of a service account, from Settings → Developers → Service accounts, that may create and export designs, and your workspace's organization ID.
  • A heycreo template for the announcement, with its ID and the IDs of the controls to fill: Create and export a design shows where to find them.
  • A property on the record to hold the link, for example Announcement image (single-line text).

1. Build the workflow​

In HubSpot, go to Automation → Workflows and create a workflow on the object your event lives on: a custom object Webinar, a deal or a marketing event. As the enrollment trigger choose the moment the material is needed, such as Record created.

Add the steps below in this order.

2. Start the design​

Add a Custom code action, language Node.js.

  • Secrets: add HEYCREO_API_KEY with your key.
  • Properties to include in code: the record's fields the design needs, here name and start_date.
Custom code: start the design
const axios = require('axios')

const ORGANIZATION_ID = '00000000-0000-0000-0000-000000000000'
const TEMPLATE_ID = 'TEMPLATE_ID'
const API = `https://app.heycreo.io/api/organizations/${ORGANIZATION_ID}`

exports.main = async (event, callback) => {
const { name, start_date } = event.inputFields
const headers = { Authorization: `Bearer ${process.env.HEYCREO_API_KEY}` }

const text = (controlId, value) => ({
kind: 'control',
scope: {},
controlId,
value: { valueType: 'text', value },
})

const { data: design } = await axios.post(
`${API}/posts`,
{
name: `Webinar: ${name}`,
templateId: TEMPLATE_ID,
sizes: ['linkedin-post'],
scopedValues: [
text('HEADLINE_CONTROL_ID', name),
text('DATE_CONTROL_ID', new Date(Number(start_date)).toLocaleDateString('de-DE')),
],
},
{ headers },
)

await axios.post(`${API}/posts/${design.id}/exports`, {}, { headers })

callback({ outputFields: { designId: design.id } })
}

Under Data outputs, add designId as a string. Custom code may run for 20 seconds; these two requests take a second or two. The rendering itself happens afterwards in heycreo.

3. Wait​

Add a Delay action of five minutes. An image is usually ready within seconds; the delay leaves room for a busy moment. For a video, wait longer.

4. Collect the file​

Add a second Custom code action with the same secret. Under Properties to include in code, take designId from the first action's output.

Custom code: collect the file
const axios = require('axios')

const ORGANIZATION_ID = '00000000-0000-0000-0000-000000000000'
const API = `https://app.heycreo.io/api/organizations/${ORGANIZATION_ID}`

exports.main = async (event, callback) => {
const { designId } = event.inputFields
const { data: exports } = await axios.get(`${API}/posts/${designId}/exports`, {
headers: { Authorization: `Bearer ${process.env.HEYCREO_API_KEY}` },
})

const done = exports.find((e) => e.status === 'completed')
if (!done) throw new Error(`Design ${designId} has no finished export yet`)

callback({ outputFields: { fileUrl: done.imageUrl ?? done.videoUrl ?? done.pdfUrl } })
}

Add fileUrl as a string output. If the export is not finished yet, the step fails and the workflow shows it in its history.

Add an Edit record action, choose the property Announcement image and set it to the fileUrl output of the previous action.

From here, the link is part of the record: a follow-up step can send it to the person who runs the webinar, attach it to a marketing e-mail or post it in a Slack channel.

Make it yours​

  • Several formats at once: list several entries in sizes, such as ["linkedin-post", "instagram-story"], and write one property per format in step 4.
  • Faster than a fixed delay: heycreo can report a finished export itself, through a webhook. Receiving it in HubSpot needs a workflow with the trigger When a webhook is received and the record's ID in the event, so the fixed delay is the simpler start.

See also​