APIs & Integrations

Jun22
Participant

API Domain

Hello Guys ,

I got a small tweak on my code below image ., Can you give me idea how to make the domain from the API call to be dynamic. Because we plan to install the theme to another account. right now the domain is static e.g "transforminator.com" if we installed it to the different domain it simply dont work the code  
Jun22_0-1695835343945.png.. If the other account using domain e.g "testdomain.com"  it should be generate the domain to that so the js code will work. 

Hope someone can give me some light on this one 😞

ScreenShot Tool -20230928011540.png

 

0 Upvotes
3 Replies 3
Mike_Eastwood
Recognized Expert | Gold Partner
Recognized Expert | Gold Partner

API Domain

Hi @Jun22 

 

HubSpot has a number of variables available in diffrent places (e.g. templates, modules, emails, etc.). Try this:

 

 

var company_domain = "{{ company_domain }}";

 

 

Have fun

Mike

 

Mike EastwoodMike EastwoodHere to learn more about HubSpot and share my HubSpot Knowledge. I'm the founder of Webalite a HubSpot Partner Agency based in Wellington, New Zealand and the founder of Portal-iQ the world's first automated HubSpot Portal Audit that helps you work smarter with HubSpot.

0 Upvotes
Jun22
Participant

API Domain

Hello sir, New to this, 

How do i placed that variable into the code I tried this one below but didn't work 😞

// Require axios library to make API requests
const axios = require("axios");
var company_domain = "{{company_domain}}";
// This function is executed when a request is made to the endpoint associated with this file in the serverless.json file
exports.main = async (context, sendResponse) => {
// Use axios to make a GET request to the search API
const config = {
method: "get",
url: `https://api.hubapi.com/crm/v3/objects/contacts/${context.contact.vid}/associations/deals`,
headers: {
Authorization: "Bearer pat-na1-1d1c158f-6f71-4669-b3e9-0d0fa47b89b2",
},
};

try {
const deals = [];
const { data: dealIds } = await axios(config);
for await (const dealId of dealIds.results) {
const { data: deal } = await axios.get(
`{company_domain}/_hcms/api/congratsdeal_new?id=${dealId.id}`
);
deals.push(deal);
}
console.log(company_domain)
sendResponse({ statusCode: 200, body: JSON.stringify(deals) });
} catch (error) {
sendResponse({ statusCode: 400, body: JSON.stringify(error) });
}
};
0 Upvotes
Mike_Eastwood
Recognized Expert | Gold Partner
Recognized Expert | Gold Partner

API Domain

Hi @Jun22 

 

If you are using a Serverless Function you don't need to specify the domain name.

 

This article was helpful for me: https://developers.hubspot.com/docs/cms/data/serverless-functions

 

Mike