⚙ 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 Respuestas 0

0 Respuestas

Aún no hay respuestas para esta publicación.

Por ahora, ningún usuario ha respondido a esta publicación. Vuelve pronto para ver si alguien tiene la solución o envía tu propia respuesta si sabes cómo ayudar. Cada grano de arena cuenta.

Responder esta publicación

¿Necesitas ayuda para responder? Echa un vistazo a las pautas de la comunidad