CMS Development

Member | Diamond Partner
Member | Diamond Partner

External API to populate custom module



I wish to populate a custom module with data from an external API, which requires an api_key in the request header in order to authorize. I currently receive the response 401 on my request. I have followed the in order to create serveless functions, with bad luck. I have put my api-key as a secret with the HubSpot Cli. Code is below: 


congratulations.js in my .functions-folder 



var axios = require("axios");
var API_KEY = process.env.API_SECRET_KEY;

exports.main = (context, sendResponse) => {
  var config = {
    method: "GET",
    url: ``,
    headers: {
      "X-Api-Key": API_KEY,
    .then(function(response) {
      sendResponse({ body: { response: }, statusCode: 200 });
    .catch(function(error) {
      sendResponse({ body: { error: error.message }, statusCode: 500 });




and this is mye serverless.json



  "runtime": "nodejs12.x",
  "version": "1.0",
  "secrets": ["API_SECRET_KEY"],
  "endpoints": {
    "congratulations": {
      "method": "GET",
      "file": "congratulations.js"




Do you know why I get 401 response - am I missing something? And is this the easiest way to populate a custom module with data from external API? Please let me know if there is any better way to do it - or let me know if HubSpot does not support external APIs to populate modules.. 


Thank you in advance! 

1 Reply 1
HubSpot Product Team
HubSpot Product Team

External API to populate custom module

Hello @HSollie 

Welcome to the Community!

@piersg , @jpsanchez  could you all help take a stab at this? 😺