Skip to content

Instantly share code, notes, and snippets.

@HubSpotHanevold
Created August 21, 2024 16:51
Show Gist options
  • Save HubSpotHanevold/0a64c93c22d6b9721a80b5b740668b0b to your computer and use it in GitHub Desktop.
Save HubSpotHanevold/0a64c93c22d6b9721a80b5b740668b0b to your computer and use it in GitHub Desktop.
A simple custom coded action to check API limits in workflows.
const axios = require('axios');
exports.main = async (event, callback) => {
const auth = 'Bearer ' + process.env.CHANGE_THIS_VALUE_TO_MATCH_YOUR_SECRET_NAME;
const email = event.inputFields['email'];
let data = JSON.stringify({
"filters": [
{
"propertyName": "email",
"operator": "EQ",
"value": email
}
]
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.hubapi.com/crm/v3/objects/contact/search',
headers: {
'Content-Type': 'application/json',
'Authorization': auth
},
data : data
};
axios.request(config)
.then((response) => {
console.log('successhappened');
console.log(JSON.stringify(response.data));
console.log(response.headers['x-hubspot-ratelimit-daily-remaining']);
let remainder = response.headers['x-hubspot-ratelimit-daily-remaining'];
callback({
outputFields: {
limit_remaining: remainder
}
});
})
.catch((error) => {
console.log('errorhappened');
console.log(error);
console.log(error.headers['x-hubspot-ratelimit-daily-remaining']);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment