Home
Support Forums

This api works only in gatsby node js how i can make it in click event and submit data

Hello i have a node js api call to post an api i added my code in gatby node.js worked but when ever I put in in gatsby normal page I get a lot of errors any idea i would like to add on click event to my code

var request = require("request");

var options = { method: 'POST',
  url: 'https://api.hubapi.com/contacts/v1/contact/',
  qs: { hapikey: 'demo' },
  headers: 
   { 
     'Content-Type': 'application/json' },
  body: 
   { properties: 
      [ { property: 'email', value: 'testingapis@hubspot.com' },
        { property: 'firstname', value: 'test' },
        { property: 'lastname', value: 'testerson' },
        { property: 'website', value: 'http://hubspot.com' },
        { property: 'company', value: 'HubSpot' },
        { property: 'phone', value: '555-122-2323' },
        { property: 'address', value: '25 First Street' },
        { property: 'city', value: 'Cambridge' },
        { property: 'state', value: 'MA' },
        { property: 'zip', value: '02139' } ] },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

this code doeans twork in normal gatsby page
but its working in gatsby-node . js file

Hey there, @userweb :wave:

Thanks so much for reaching out. Can you please share your site name as well as your project repo? This will help us look into this further.

Hi @userweb

You have already asked exactly the same question in I added node js code to gatsby node js want to do on click event I have previously provided methods for your to add an event listener to your page.

1 Like

Good spot, @coelmay.

@userweb, we ask that Forums members keep related questions to one thread. This is to streamline support conversations. I am going to close this thread current thread, and you can continue collaborating on this: I added node js code to gatsby node js want to do on click event

1 Like