⚙ Operations Hub

KyleJepson
HubSpot Employee
HubSpot Employee

VIDEO: API calls in custom-coded workflow actions

Today I've been working on a workflow action that'll take a deal's close date and generate an expiration date that's one year later. Here I am talking through the code I wrote (~5 min):

 

 

One thing I learned in this process that I didn't know before is that HubSpot has two different kinds of date properties: date properties (date only, no time) and datetime properties (date AND time). Inside your HubSpot account, they'll both be labeled "date picker properties," but in the background, they operate differently.

 

All of HubSpot's standard date properties are datetime properties. When you create a custom "date picker" property inside your account, it'll always be a date property. The only way to create a custom datetime property is by using the API.

 

My custom action was pulling Close Date (datetime), increasing the year by 1, then updating Expiration Date (date) -- and it was getting all kinds of errors. But then I used the API to create a custom datetime property, and suddenly it worked.

 

Here's my code:

 

 

const hubspot = require('@hubspot/api-client');

exports.main = (event, callback) => {
  callback(processEvent(event));
}

function processEvent(event) {
  const hubspotClient = new hubspot.Client({
    apiKey: process.env.HAPIKEY
  });
  
  let dealId = event.object.objectId;
  hubspotClient.crm.deals.basicApi.getById(dealId, ["closedate"])
    .then(results => {
      let expirationDate = new Date(results.body.properties.closedate);
    
expirationDate.setFullYear(expirationDate.getFullYear() + 1);
    hubspotClient.crm.deals.basicApi.update(
      dealId,
      {properties: {["dealexpiration"]: expirationDate}}
    )
    
    })
}

 

 

 

 

0 Replies 0

0 Replies

No replies on this post just yet

No one has replied to this post quite yet. Check back soon to see if someone has a solution, or submit your own reply if you know how to help! Karma is real.

Reply to post

Need help replying? Check out our Community Guidelines