FilesHTTPHubSpot

Template: HubSpot to JSON - Companies

Summary

This template retrieves company data from HubSpot and downloads it to a local fileshare as a single JSON file.

Template

Prerequisites

This template assumes that the following prerequisites are in place:

  • HubSpot access token is accessible.
  • The Frends agent has access to the local fileshare to which the resulting JSON file will be saved.

Implementation and Usage Notes

This template retrieves companies from the HubSpot API, which returns paginated results with each page displaying a maximum of 100 companies. In case more than one result page exists, the template makes sequential calls to fetch each page, using the URL provided in the paging.next.link property of the previous response. The processing of pages continues until no next page link is found.

The companies from each page are collected into a JArray list in JSON format. You can adjust the fetched company properties and associations within the process variables.

After processing all results, the company data is written to a single JSON file. The full path to which the file is saved, including the file name, is determined in the process variables. If a file with the same name exists in the specified path, the file will be overwritten. You can change this in the write task's settings.

Error Handling

If a request to the HubSpot API fails, the template throws an exception stating the error message and stops without writing the file. For any transient errors, the connection to HubSpot is tried 5 times with each request.

Template Process Variables

Name Description
HubSpotAccessTokenSecret The access token for the HubSpot API.
TargetFilePath The full path of the resulting JSON file, including the file name.
CompanyProperties The company attributes fetched with the HubSpot API request.
CompanyAssociations The companies' connections to other object types fetched with the HubSpot API request.
An unhandled error has occurred. Reload 🗙