HubSpot

NEW: we have a free HubSpot app that you can use

You can easily install the HubSpot app directly from our portal:

  • Log in to portal.print.one

  • Go to Integrate > Integrations > HubSpot and click Install


If you do not want to use the app, your HubSpot account must meet the following condition:

  • You must have access to the Workflow builder under the "automate" heading in the HubSpot dashboard.

This article will explain how to implement Print.one in your HubSpot workflows. In doing so, the following steps will be explained:

  1. Creating a HubSpot workflow;

  2. Linking the Print.one API Key to HubSpot;

  3. Adding a Print.one action to the workflow;

  4. Testing the action.

Linking Print.one with HubSpot can be done in Javascript (NodeJS) and Python. These are flexible programming languages supported by HubSpot. In this example, only Javascript will be used.

Links to consult

1. Creating a HubSpot workflow

Go to your HubSpot dashboard and click on "Automation" -> "Workflows" at the top of the menu. From there, click on "Create workflow" at the top right. Choose a template, or start from scratch.

In the workflow, click on the plus and in the menu that follows on "Custom code". See also the image below.

2. Linking the Print.one API Key to HubSpot

After creating the custom code action in the workflow, a menu appears on the right where the action can be edited. There, under "Secrets", click "Add secret", as shown in the image below.

In the pop-up, enter a name (letters and low dashes only) and a Print.one API key as the value. Print.one API keys can be found at https://portal.print.one/devs/apikeys.

The Print.one API Key is now linked to HubSpot.

3. Adding a Print.one action to the workflow

Add properties

In the same menu, it is possible to add properties to the code action. To do so, click "Add property" and add all desired properties. To send cards to a person, it is important that at least the following data is known:

  • A name;

  • An address;

  • A postcode;

  • A city;

  • A country.

If these details are missing, a card may not arrive correctly to the recipient. See the image below for the data for this example.

Call print.one with desired properties

To convert the desired data into a map, the code snippet below can be used. The code also includes comments with additional explanations. Don't forget to enter your own data in all fields.

HubSpot code for calling Print.one
const axios = require("axios");
// This function causes properties to start with a capital letter
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
exports.main = (event, callback) => {
// Import the data selected in the previous header.
const firstname = capitalizeFirstLetter(event.inputFields["firstname"]);
const lastname = capitalizeFirstLetter(event.inputFields["lastname"]);
const salutation = capitalizeFirstLetter(event.inputFields["salutation"]);
const animalname = capitalizeFirstLetter(event.inputFields["animalname"]);
const address = capitalizeFirstLetter(event.inputFields["address"]);
const zip = event.inputFields["zip"]; // The postal code does not need to start with a capital letter
const city = capitalizeFirstLetter(event.inputFields["city"]);
const country = capitalizeFirstLetter(event.inputFields["country"]);
axios
.post(
"https://api.print.one/v2/orders",
{
sender: {
name: "Your company name",
address: "Your address",
postalCode: "Your postal code",
city: "Your city",
country: "Your country",
},
recipient: {
name: firstname + " " + lastname,
address: address,
postalCode: zip,
city: city,
country: country,
},
templateId: "<<Fill in the template ID here>>",
finish:"<<Fill in the desired finish here>>",
mergeVariables: {
// Use the desired merge variables in this section
Salutation: salutation,
Surname: lastname,
NameAnimal: animalname,
},
billingId: "<<Fill in a billing ID here (not required)>>"
},
{
headers: {
"x-api-key": process.env.Print_One_API_Key, // Did you give the API key a different name? If so, modify it here.
},
}
)
.then((result) => {
// The following code is executed when a map is successfully sent.
console.log(result.data);
callback({
outputFields: result.data,
});
})
.catch((error) => {
// The following code is executed if something went wrong when sending a card.
console.error(error.response.data);
throw error.response.data;
});
};

Finally, click save to save the action.

4. Testing the workflow

Now that the action is finished, it can be tested. To do so, click on "Testing" in the workflow menu. Click on "Testing" in the menu of the action. Enter the data you want to use for testing and click "Test". If everything went well, the workflow will have been executed successfully and a card will have been sent to the specified data. The map will also show up in the Print.one dashboard.

Help, something isn't working!

Don't worry, when testing the action, a clear error message will appear, for example the one below. In that error message you can clearly see which template is not set correctly.

Example of error JSON Body
1{
2 "statusCode": 400,
3 "message": [
4 "'tmpl_4fd010d-16d1-4bfb-b043-ae7f3520f3ea' does not exist.".
5 ]
6}

Should you still encounter a problem, you can always consult HubSpot's documentation.