Do HubSpot APIs support CORS / AJAX requests? I am getting error while calling ajax call


#1

hi,
I would like to get blog details of your website through ajax call but I am getting “Uncaught SyntaxError: Unexpected identifier” please address it as soon as possible.
$.ajax({
type:“GET”,
dataType: “jsonp”,
jsonpCallback:‘callback’,
contentType:“application/json”,
url:"https://api.hubapi.com/content/api/v2/blog-posts/"+5067937629+"?hapikey=**********"
success: function (data) {} });


#2

@nagavalli We do not support CORS requests. All requests must be made server-side


#3

1.when we request blog data in Hubspot it is working fine where as we publish that module on our page it raising Allow Origin Access error, our blogs total content working only through HubSpot. our requirement is we want to pull our blog data through Hubspot to our site.

2.Is Hubspot support c# coding can we write c# code if yes where we have to add that data.

3.If we want to pull all Blog related JSON data to your site what are the different alternatives.

Thanks,
Nagavalli


#4

@nagavalli

  1. How are you publishing it onto your page. Are you making a Frond-End request?

  2. HubSpot does not support adding any sort of server-side code to it.

  3. Do you mean pulling data from our site? The only option is to do it through the API.


#5

@pmanca

  1. our company have Hubspot Marketing and sales account through that they will publish the Blogs website http://pixentia.com/ in this website total Blogs and resources are completely handled by Hubspot.

our requirement is we have to pull blogs data based on the topicId we have to give one popup based on topicId.

Thanks,
Nagavalli


#6

@nagavalli You won’t be able to pull the actual Blog data through the API. If you want to pull a blog you can use this endpoint here:

This won’t return the analytics for you.

You can get some information about a specific topic from here:


#8

@nagavalli This is a developer’s forum and not a support forum. We don’t offer phone support through this medium.


#9

@pmanca
Ok thanks,
Actually, we are getting complete JSON data using URLhttps://api.hubapi.com/content/api/v2/blog-posts/BLOGContentID?hapikey=*****, through this URL but when we publish that Module to Pixentia website it through an uncaught syntax error unexpected token for blogs data.
when we run the same code in Hubspot it is working fine.Issue after we publish that data.
Thanks


#10

@nagavalli Are you trying to move one blog from one HubSpot account to a different HubSpot account? Where is your Pixentia website hosted? If it isn’t hosted on HubSpot the page where you are trying to push it to, the syntax error could be that the other system wouldn’t understand HubL which is our templating language.


#11

@pmanca
No, we are not moving data from one account to another account we are creating Modules and simply publishing that modules on our site.

after publishing it automatically reflect in Pixentia.


#12

@nagavalli You are going to run into some code issues as our modules are wrapped in HubL which is a proprietary templating language. You will need to change/edit the code a bit so it will be compatible with Pixentia.


#13
<div class="modal">
<div class="modal-close-outer">
	<div class="modal-close">X</div>
</div>
<div class="Test_Modal"></div>

this is what I write in Module it is working pretty good in Hubspot but after publish it is not working in Pixentia site.


#14

Does that part actually work for you? We don’t allow Front-End requests to our APIs and require server-side requests. I’m surprised you are getting a blog properly returned to you with that.


#15

yes, I am getting complete Blog data at the console in Hubspot. with API key.


#16

In the console do you see any HubL? It would look similar to Jinja. The browser would not be able to render this and that is why you are receiving that error.


#18

@pmanca, I am stuck with similar issue, My motive is simple to get data from crm, using hubspot api,

I did try to use ajax, dataType: “json”,
$.ajax({
type:“GET”,

dataType: “json”,
jsonpCallback:‘callback’,

url:"https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=1232-sfesfe-a323432-23423423-fsf"
success: function(data) {
// console.log(data);
},
error: function() {
console.log(“fail”);
// alert();
}

});

Result I got cross origin error :slight_smile:
Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

  1. I used datatype : jsonp

$.ajax({
type: “GET”,

dataType: "jsonp",
jsonp: "callback",
 crossOrigin: true,
jsonpCallback: "my_callback",
 url: "https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=1232-sfesfe-a323432-23423423-fsf",
headers:{"Content-Type":"text/html; charset=utf-8"},
cors:false,
success: function(data) {
   
    console.log(data);
},
error: function() {
    console.log("fail");
   
}

Result : I got error
“Uncaught SyntaxError: Unexpected token : ”

------------------------------------------------------ its been like 3 days to figure outo some thing

On our blog pages we need to pull data from crm, contact details, and on basis of these details we need to create blog post dynamically;

@nagavalli @pmanca , we do get data on console,

why you have https://developers.hubspot.com/docs/methods/contacts/get_contacts

if we can’t use it, I need to pull user data, by making call to crm
https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=demo

being on same domain it dosen’t help::


#19

@ume.a We only support server-side requests. Client-side requests aren’t typically allowed and if you see it in the browser console it is not by design.


#20

An easy way I have found to make requests to the API is using Google App Engine. It’s free to use on the first tier and it’s very easy to set up an endpoint that makes requests to the API. I am using the Java API for this so I don’t know what languages you’re fimiliar with but that has proven to be the cheapest and easiest way to avoid CORS errors. IME most APIs do not support cross origin requests so this is a helpful method to use with any API. This method also adds a layer of security to your API key as you can let the server only take requests from whitelisted URLs.