Error creating calculation property with Properties API

I found a workaround for creating calculated properties that only involve number properties and at most one non-number property. As of this writing, you can’t create a calculated property that references other properties by only using the Properties API. This is clearly a bug in the Properties API implementation and HubSpot should fix it.

The workaround involves creating the calculated property in the Hubspot Portal and then updating the property using the Properties API.

The steps of the workaround:

  1. In the Hubspot Portal click on the Settings button, the gear icon in the top right
  2. Click on Properties in the left sidebar
  3. Select the object that you’ll create a property on
  4. Click the Create Property button on the right

  1. Fill out the basic information in the form and click Next

  1. Select Calculation as the Field Type and click Build calculation

  1. At this point we need to create a dummy calculation that exists solely for the purpose of allowing us to use specific properties in the custom calculation formula that we’ll set later. Any properties you want to use in your custom calculation must be included in this dummy formula. For example, based on the screenshot below, we’ll be able to use Quote Lines, Annual Contract Value, and Priority in our custom calculation formula, but no other properties. Any other properties will trigger an error when we set our custom formula.

  1. Click Create. The Calculation property is created, but it doesn’t have the formula we want.
  2. To set the formula we want, we update the “calculationFormula” attribute on the property using the “Update a Property” endpoint of the Properties API. An example request body where you’re only updating the calculationFormula:

{
“calculationFormula”: “if string(priority)=‘high’ then hs_acv/quote_lines else 5”
}

  1. Wait a few minutes and look up some values for your calculated property. You’ll see that it calculates according to your new formula.

Limitations: You can only use 1 non-number property in the calculation. You can only reference that 1 non-number property in the “Additional Condition” section of the calculation builder in the HubSpot Portal. You can use an arbitrary number of number properties since you can keep using “Add to equation” button and including other properties.

You can only use properties listed in the HubSpot Portal’s calculation builder. So some built-in properties like hs_object_id can’t be used.