APIs & Integrations

StefSchad
Member

Custom code to fetch Sequence name based on sequence id

SOLVE

Hi,

I want to fetch the name of the sequence, based on the contact property "Last sequence enrolled" (which is an ID) and save it into a custom contact field (that I called "Last sequence enrolled name"). I created a private app and tried a custom code into a workflow. I always have an error message: "Request failed with status code 404" but I can't fix it. If someone could help, it would be great.

 

Here is the code:

 

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

exports.main = async (event, context, callback) => {

const HUBSPOT_API_KEY = process.env.xxxx;


const hubspotClient = new hubspot.Client({ accessToken: HUBSPOT_API_KEY });


const SEQUENCE_ID = 'hs_latest_sequence_enrolled';


const CONTACT_ID = 'hs_object_id';

let sequenceName;


const url = `https://api.hubapi.com/automation/v3/sequences/${SEQUENCE_ID}`;

const headers = {
Authorization: `Bearer ${HUBSPOT_API_KEY}`
};

try {
const response = await axios.get(url, { headers });
sequenceName = response.data.name;
console.log(`The name of the sequence is : ${sequenceName}`);

// Update the data of my custom property
const urlUpdate = `https://api.hubapi.com/contacts/v1/contact/vid/${CONTACT_ID}/profile`;
const payload = {
properties: [
{
property: 'last_sequence_enrolled_name',
value: sequenceName,
},
],
};

await axios.post(urlUpdate, payload, { headers });
console.log(`The property "last_sequence_enrolled_name" was updated on this ${CONTACT_ID} with this value : ${sequenceName}`);
} catch (error) {
console.error(`Update error : ${error.message}`);
}
}

0 Upvotes
1 Accepted solution
coldrickjack
Solution
Guide

Custom code to fetch Sequence name based on sequence id

SOLVE

Hi @StefSchad,

 

I believe you are getting that 404 as the endpoint doesn't currently exist as part of HubSpots APIs. Did you find that endpoint documented somewhere online and if so can you share documentation? 

View solution in original post

0 Upvotes
1 Reply 1
coldrickjack
Solution
Guide

Custom code to fetch Sequence name based on sequence id

SOLVE

Hi @StefSchad,

 

I believe you are getting that 404 as the endpoint doesn't currently exist as part of HubSpots APIs. Did you find that endpoint documented somewhere online and if so can you share documentation? 

0 Upvotes