Hello guys:
can anyone on how can i link react js project to hubspot ?
I have tried 2 method (the first one it’s suggestion Cors Problem and the second ; TypeError: url_1.URL is not a constructor).
here’s my code if someone could help:
import React, { useState } from “react”;
import { Client } from “@hubspot/api-client”;
export default function ContactForm() {
const [firstName, setFirstName] = useState(“”);
const [lastName, setLastName] = useState(“”);
const [email, setEmail] = useState(“”);
const [phoneNumber, setPhoneNumber] = useState(“”);
const [message, setMessage] = useState(“”);
const handleSubmit = async (e) => {
// console.log(import.meta.env.VITE_Hubspot_API);
e.preventDefault();
const data = {
properties: [
{“property”: “firstname”, “value”:firstName},
{“property”: “lastname”, “value”:lastName},
{“property”: “email”, “value”:email},
{“property”: “phone”, “value”:phoneNumber},
{“property”: “message”, “value”:message},
],
};
const hubspotClient = new Client({accessToken: import.meta.env.VITE_Hubspot_API});
console.log(hubspotClient);
try{
const createContactResponse = await hubspotClient.crm.contacts.basicApi.create(data);
console.log(createContactResponse);
}catch(e){
console.error(e);
}
setFirstName(“”);
setLastName(“”);
setEmail(“”);
setPhoneNumber(“”);
setMessage(“”);
};
return (
<form onSubmit={handleSubmit} className=“mt-[15%]”>
<input name=“firstname” placeholder=“First Name” value={firstName} onChange={(e) => setFirstName(e.target.value)}/>
<br />
<input name=“lastname” placeholder=“Last Name” value={lastName} onChange={(e) => setLastName(e.target.value)}/>
<br />
<input name=“email” placeholder=“Email” value={email} onChange={(e) => setEmail(e.target.value)}/>
<br />
<input name=“phoneNumber” placeholder=“Phone Number” value={phoneNumber} onChange={(e) => setPhoneNumber(e.target.value)}/>
<br />
<input name=“message” placeholder=“Please add information regarding your inquiry” value={message} onChange={(e) => setMessage(e.target.value)}/>
<br />
<button type=“submit”>Submit</button>
</form>
);
}