APIs & Integrations

DavidFJones
Member | Platinum Partner
Member | Platinum Partner

Using form guid as secret / environment variable

Hey all,
I'm building a theme that will need to have a custom html form that I have created on one of the pages, and when the user submits this form I need to use a serverless function/api call to send the data.

Here's the problem. My understanding is that the only way to Submit Form Data  via api is to also know that forms unique GUID. When the form is first associated with a page in hubspot, this GUID is generated automatically. Because of this, the current way to call the api is to hard code this GUID value into the js file.

I'm wondering if there is any better way to automate this. Ideally someone should be able to use this theme and not have someone else set up any code for them. One thought I had would be to use the Get Forms API , check for the form name, and then set the GUID if there is a match. The problem I have with this method is that it means everytime a user goes to submit this form, the serverless function will need to make 2 api calls, and one of them will need to loop through every form on that hubspot account until it finds a match.

Another idea I had/question I had about this as well. Is there any way that I could instead check if this GUID exists, and if not make the big api call to get all forms and find a match, and then dynamically/automatically save the guid as a secret in my severless.json file? This way that big call/loop only needs to happen the one time. Would this even be possible? And are there any security risks/concerns that I am unaware of if I were to go in this direction?

0 Upvotes
1 Reply 1
WendyGoh
HubSpot Employee
HubSpot Employee

Using form guid as secret / environment variable

Hey @DavidFJones,

 

Thanks for the detailed write up! 

 

That is defnitely a possible workaround and I do not believe there's any security risks/concerns that I'm aware of if your team implement this check. 

 

You can use the Get a form by its unique ID | Forms API to check if a form guid exists. If it doesn't, it'll return a 404 not found error with the following message: 

message:"No form found with guid 'the form id'",

If it exists, it'll return a 200 response with the form details.

0 Upvotes