APIs & Integrations

IVolos3
Member

Angular Universal - hubspot http request blockes by CORS

Hi all!

I currently getting a CORS error when sending HTTP requests from a web client (Angular web application). Thing is, earlier such requests was sucessfull on testing server, but after moving to production I constantly getting CORS error.

Is there any setup needed for this from the app.hubspot profile ? I want to be able to send HTTP requests to create or update contacts only with hapi key, without using back-end (site I have is a simple landing page). How can I add my domain and not get that error response? I already have added my external domain in advanced tracking settings, and enable automatic cross-domain linking. Tracking code is installed on site and fires sucessfully.

Here is Angular function I use to send http request to hubspot:

 

createOrUpdateContactByEmail(contactData: object) {
    const email = this.contactService.getContactEmail();
    const myHeaders = new HttpHeaders().set('Content-Type', 'application/json');
    let params = new HttpParams();
    params = params.append('hapikey', this.apiKey);

    const payloadBody = {"properties": [{}]}
    payloadBody.properties = Object.entries(contactData).map(([propertyName, value]) => {
      return {property: propertyName, value: value};
    });
    console.dir(payloadBody);
 
    return this.http.post<any>(`${this.baseUrl}contacts/v1/contact/createOrUpdate/email/${email}/`,
      payloadBody,
      {headers: myHeaders, params: params}
    ).subscribe(responseData => {
      console.dir(responseData);
    });
  }
}


Such request are send to hubspot:
https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email//?hapikey=MY_API_KEY

And this is full error log I get:

image_2022-05-20_14-13-01.png

 

I really appreciate any help you can provide!

0 Upvotes
1 Reply 1
Jaycee_Lewis
Community Manager
Community Manager

Angular Universal - hubspot http request blockes by CORS

Hey, @IVolos3 Thank you for the details. Let's see if our community has some insight into this error and thoughts on getting it resolved  – @jpsanchez @louischausse @Indra do you have any experience here? 

 

Thank you! – Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes