APIs & Integrations

sjay
Mitglied | Diamond Partner
Mitglied | Diamond Partner

Can we call 3rd party rest API from our HubSpot Custom Module ?

Hi Mates,

 

I am trying to integrate the 3rd party REST API in our HubSpot custom module.  So that I thought to access it on my webpage.

 

For Ex: https://via.ritzau.dk/json/v2/releases  --> Is my 3rd Party REST API

 

Using postman service, I’ve generated the below code and integrated it into one of our webpages. But it was returning an error by saying that, it has been blocked by CORS policy (please refer to the below error image).

 

Can anyone help me out here?

 

Code : 

var settings = {

  "url": "https://via.ritzau.dk/json/v2/releases",

  "method": "GET",

  "timeout": 0,

};

 

$.ajax(settings).done(function (response) {

  console.log(response);

});

 

error.png

 

Thanks,

Sanjay

0 Upvotes
2 Antworten
dimitreliasb
Mitwirkender/Mitwirkende

Can we call 3rd party rest API from our HubSpot Custom Module ?

Try putting this in front of your url string 

https://cors-anywhere.herokuapp.com/

to make it like this: 

https://cors-anywhere.herokuapp.com/https://via.ritzau.dk/json/v2/releases

that fixes the error...

WendyGoh
HubSpot Employee
HubSpot Employee

Can we call 3rd party rest API from our HubSpot Custom Module ?

Hey @sjay,

 

Could you try removing the code and see the error is still showing?

 

Generally, as Connor mentioned on this community thread:

 

"this means your domain is blocking these requests since it violates the CORS rules set by the browser. It's blocking them because your domain you're requesting from differs from the one you're requesting to. This does a much better job of explaining this than I can: https://stackoverflow.com/questions/20035101/why-does-my-javascript-get-a-no-access-control-allow-or...

0 Upvotes