HubSpot API - trying to update contact record

144 Views Asked by At

young developer here getting into working with apis for the first time. Goal of my project is to update a HubSpot custom property that I created to hold a Big Commerce customer ID. Having trouble with trying to pull the test record I am using. not sure whether I am making the request properly or not (again I am new to apis)

bcCustomerEmail hold the value of the email I pulled off big commerce record.

summary, trying to pull Hubspot contact record based off email, and then adding the value of bcCustomerId to customer property

(I am not using the the node client library) and do nto plan to for this

const hubspotEndpoint = https://api.hubapi.com/crm/v3/objects/contacts/?email=${bcCustomerEmail};

  const hubspotApiKey = process.env.HUBSPOT_ACCESS_TOKEN;
  const hubspotHeaders = {
    "Content-Type": "application/json",
    Authorization: `Bearer ${hubspotApiKey}`, 
  };
  ///// hubspot payload request
  const hubspotPayload = {
    properties: ["email", "big_commerce_customer_id"],
    idProperty: "email",
    inputs: [
      {
        id: bcCustomerEmail,
      },
    ],
  };

  try {
    const hubspotReponse = await axios.patch(
      hubspotEndpoint,
      hubspotPayload,
      {
        headers: hubspotHeaders,
      }
    );
    const contactId = hubspotReponse.data;
    console.log(contactId);
  } catch (error) {
    console.error("Error fetching contact from HubSpot:", error);
  }
})

.catch((error) => {
  console.error("An error occurred:", error);
});

});

0

There are 0 best solutions below