Back to listing

Create an Excel export from a HubSpot object

Custom-Coded Workflow Action, Operations Pro/Ent



The imports and exports API is pretty new in HubSpot but it adds many new capabilities. 

The exports API is particularly useful for grabbing an Excel file of a specific object type. This code snippet does exactly that and is ideally combined with a scheduled workflow action in Operations Hub Professional/Enterprise. A common use case is to back up data in another system or handle some internal reporting process that depends on static snapshots at specific time intervals. 



Language: JavaScript

const axios = require('axios');
const accessToken = process.env.secretName;
exports.main = async (event, callback) => {
const propertyName = "email";
  const propertyValue = event.inputFields['propertyValue'];
  const objectType = "contact";
  const apiUrl = '';
  const headers = {
    authorization: `Bearer ${accessToken}`,
    'content-type': 'application/json'
  const data = {
    exportType: 'VIEW',
    exportName: `Recurring export of ${objectType} from HubSpot`,
    format: 'xlsx',
    language: 'EN',
    objectType: objectType,
    objectProperties: [
    publicCrmSearchRequest: {
      filters: [
          value: propertyName,
          propertyName: propertyValue,
          operator: 'EQ'
      sorts: [
          propertyName: 'createdate',
          order: 'DSC'
    .post(apiUrl, data, { headers })
    .then(response => {
      const exportId =;
      console.log("The export ID is: " + exportId);
        outputFields: {
          exportId: exportId
    .catch(error => {

How can SpotDev support your business?

HubSpot Migrations

Move from Salesforce, Dynamics, Pipedrive or any CRM to HubSpot with SpotDev.

Learn more

HubSpot Integrations

Add advanced functionality to your HubSpot portal with API development services.

Learn more


Align your sales, marketing and service teams to break down silos and trigger growth.

Learn more