Hi. I’ve been searching for a way to send a contact info to an external server using a button on custom module and couldn’t find anything that might help on my specific problem.
So the context is as follow:
I need to send some contact info to an external server. The trigger is a button on a custom module.
My initial approach was to add a `click` event listener to the button and on that event handler function try to acces the contact info and send a http request with the required info.
But I couldn’t find a way to access the contact info on the module js file.
Is there a correct way of doing this?
The reason for this approach was because the external server will respond with a redirect response to another web site, and the only way to have the browser redirect upon a http response was to trigger the request directly from the javascript on the hubspot website.
Hope this is enough info for the help but if not ask me to elaborate more.
Thanks!
Hi, @sidcamara
Thanks for your question. Do you have access to an external server or serverless functions?
Have you looked at:
- setting the cookie
- grabbing the
hubspotutk
- using your server to make a request to get the Contact from the
hubspotutk
- add the specific properties you want returned to the request URL
- send a request to your external server with this data once the button is clicked
Your client-side JavaScript code would simply be responsible for triggering the server-side process, rather than having to manage multiple API requests itself. The heavy lifting is done server-side and helps with security.
If this doesn’t fit based on your limitations, please add any additional context, and we will tag in a few community members to brainstorm other workarounds.
Best,
Jaycee
Hi Jaycee and thanks for the help.
Answering your question, yes the external server is mine and I have control over it.
My current solution was to have the button module like this
then access the contact id with the javascript code, and trigger the http request sending the contact id to the server. Then the server with the id can then request the contact info needed from hubspot(server-to-server). I’m not a big fan of this solution, but with a private page I can be certain that the id that I’m sending to the server is the correct one.
The reason to trigger the request from the button module JS is because the http response from the server will be(if nothing goes wrong) a redirect to a external web site page (external from hubspot and from my app, it is a third party web site).
I couldn’t see any other way to have this redirect behaviour.
If you have a suggestion that I ovewrlooked I appreciate the sharing. I understand and agree that it would be more secure and lighter on the client-side but I couldn’t see any other way of doing this.
In the mean time I will explore your suggestion of using the hubspotutk .