Getting error has been blocked by CORS policy when making api call











up vote
0
down vote

favorite












I am getting the following error when I am trying to make an api call to kickstarter Staff pick json endpoint



This is what the error exactly looks like




localhost/:1 Access to XMLHttpRequest at
'https://www.kickstarter.com/discover/recommended?format=json' from
origin 'http://localhost:3000' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.




I have previously encountered this error but that was when I was trying to make a local API call.



I known I can enable cors on my browser which might possibly fix the error but I am trying to avoid it.



Any ideas or fixes?



I am using axios for making api calls



axios.get("https://www.kickstarter.com/discover/recommended?format=json").then(response => {


[Update:] Can someone also help me in figuring out how we can use it with Promise.



 let Base_url = axios.get(base_url)
let StaffPick = axios.get(staffPick)


return Promise.all(Base_url, StaffPick).then(response => {


Where staff pick is https://www.kickstarter.com/discover/recommended?format=json
and
base_url is: http://coincap.io/map










share|improve this question
























  • If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
    – charlietfl
    Nov 10 at 20:18












  • @charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
    – KuchBhi
    Nov 10 at 20:21










  • Do a web search for "ajax proxy"
    – charlietfl
    Nov 10 at 20:21










  • Seems fine when simply hitting that end-point from a browser... Share your get request code here...
    – SakoBu
    Nov 10 at 20:22










  • @SakoBu you clearly didn't try it using XMLHttpRequest() or fetch() which is where CORS kicks in
    – charlietfl
    Nov 10 at 20:24

















up vote
0
down vote

favorite












I am getting the following error when I am trying to make an api call to kickstarter Staff pick json endpoint



This is what the error exactly looks like




localhost/:1 Access to XMLHttpRequest at
'https://www.kickstarter.com/discover/recommended?format=json' from
origin 'http://localhost:3000' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.




I have previously encountered this error but that was when I was trying to make a local API call.



I known I can enable cors on my browser which might possibly fix the error but I am trying to avoid it.



Any ideas or fixes?



I am using axios for making api calls



axios.get("https://www.kickstarter.com/discover/recommended?format=json").then(response => {


[Update:] Can someone also help me in figuring out how we can use it with Promise.



 let Base_url = axios.get(base_url)
let StaffPick = axios.get(staffPick)


return Promise.all(Base_url, StaffPick).then(response => {


Where staff pick is https://www.kickstarter.com/discover/recommended?format=json
and
base_url is: http://coincap.io/map










share|improve this question
























  • If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
    – charlietfl
    Nov 10 at 20:18












  • @charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
    – KuchBhi
    Nov 10 at 20:21










  • Do a web search for "ajax proxy"
    – charlietfl
    Nov 10 at 20:21










  • Seems fine when simply hitting that end-point from a browser... Share your get request code here...
    – SakoBu
    Nov 10 at 20:22










  • @SakoBu you clearly didn't try it using XMLHttpRequest() or fetch() which is where CORS kicks in
    – charlietfl
    Nov 10 at 20:24















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am getting the following error when I am trying to make an api call to kickstarter Staff pick json endpoint



This is what the error exactly looks like




localhost/:1 Access to XMLHttpRequest at
'https://www.kickstarter.com/discover/recommended?format=json' from
origin 'http://localhost:3000' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.




I have previously encountered this error but that was when I was trying to make a local API call.



I known I can enable cors on my browser which might possibly fix the error but I am trying to avoid it.



Any ideas or fixes?



I am using axios for making api calls



axios.get("https://www.kickstarter.com/discover/recommended?format=json").then(response => {


[Update:] Can someone also help me in figuring out how we can use it with Promise.



 let Base_url = axios.get(base_url)
let StaffPick = axios.get(staffPick)


return Promise.all(Base_url, StaffPick).then(response => {


Where staff pick is https://www.kickstarter.com/discover/recommended?format=json
and
base_url is: http://coincap.io/map










share|improve this question















I am getting the following error when I am trying to make an api call to kickstarter Staff pick json endpoint



This is what the error exactly looks like




localhost/:1 Access to XMLHttpRequest at
'https://www.kickstarter.com/discover/recommended?format=json' from
origin 'http://localhost:3000' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.




I have previously encountered this error but that was when I was trying to make a local API call.



I known I can enable cors on my browser which might possibly fix the error but I am trying to avoid it.



Any ideas or fixes?



I am using axios for making api calls



axios.get("https://www.kickstarter.com/discover/recommended?format=json").then(response => {


[Update:] Can someone also help me in figuring out how we can use it with Promise.



 let Base_url = axios.get(base_url)
let StaffPick = axios.get(staffPick)


return Promise.all(Base_url, StaffPick).then(response => {


Where staff pick is https://www.kickstarter.com/discover/recommended?format=json
and
base_url is: http://coincap.io/map







javascript ajax api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 20:39

























asked Nov 10 at 20:15









KuchBhi

621218




621218












  • If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
    – charlietfl
    Nov 10 at 20:18












  • @charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
    – KuchBhi
    Nov 10 at 20:21










  • Do a web search for "ajax proxy"
    – charlietfl
    Nov 10 at 20:21










  • Seems fine when simply hitting that end-point from a browser... Share your get request code here...
    – SakoBu
    Nov 10 at 20:22










  • @SakoBu you clearly didn't try it using XMLHttpRequest() or fetch() which is where CORS kicks in
    – charlietfl
    Nov 10 at 20:24




















  • If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
    – charlietfl
    Nov 10 at 20:18












  • @charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
    – KuchBhi
    Nov 10 at 20:21










  • Do a web search for "ajax proxy"
    – charlietfl
    Nov 10 at 20:21










  • Seems fine when simply hitting that end-point from a browser... Share your get request code here...
    – SakoBu
    Nov 10 at 20:22










  • @SakoBu you clearly didn't try it using XMLHttpRequest() or fetch() which is where CORS kicks in
    – charlietfl
    Nov 10 at 20:24


















If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
– charlietfl
Nov 10 at 20:18






If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
– charlietfl
Nov 10 at 20:18














@charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
– KuchBhi
Nov 10 at 20:21




@charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
– KuchBhi
Nov 10 at 20:21












Do a web search for "ajax proxy"
– charlietfl
Nov 10 at 20:21




Do a web search for "ajax proxy"
– charlietfl
Nov 10 at 20:21












Seems fine when simply hitting that end-point from a browser... Share your get request code here...
– SakoBu
Nov 10 at 20:22




Seems fine when simply hitting that end-point from a browser... Share your get request code here...
– SakoBu
Nov 10 at 20:22












@SakoBu you clearly didn't try it using XMLHttpRequest() or fetch() which is where CORS kicks in
– charlietfl
Nov 10 at 20:24






@SakoBu you clearly didn't try it using XMLHttpRequest() or fetch() which is where CORS kicks in
– charlietfl
Nov 10 at 20:24














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Try it like this and it should work:



fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));


Or the equivalent with axios...



Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15



Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere



Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS






share|improve this answer



















  • 1




    An explanation of why it should work would be helpful
    – charlietfl
    Nov 10 at 20:33










  • Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
    – KuchBhi
    Nov 10 at 20:36












  • @KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
    – SakoBu
    Nov 10 at 21:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243031%2fgetting-error-has-been-blocked-by-cors-policy-when-making-api-call%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Try it like this and it should work:



fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));


Or the equivalent with axios...



Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15



Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere



Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS






share|improve this answer



















  • 1




    An explanation of why it should work would be helpful
    – charlietfl
    Nov 10 at 20:33










  • Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
    – KuchBhi
    Nov 10 at 20:36












  • @KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
    – SakoBu
    Nov 10 at 21:09















up vote
1
down vote



accepted










Try it like this and it should work:



fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));


Or the equivalent with axios...



Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15



Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere



Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS






share|improve this answer



















  • 1




    An explanation of why it should work would be helpful
    – charlietfl
    Nov 10 at 20:33










  • Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
    – KuchBhi
    Nov 10 at 20:36












  • @KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
    – SakoBu
    Nov 10 at 21:09













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Try it like this and it should work:



fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));


Or the equivalent with axios...



Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15



Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere



Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS






share|improve this answer














Try it like this and it should work:



fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));


Or the equivalent with axios...



Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15



Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere



Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 20:38

























answered Nov 10 at 20:28









SakoBu

681317




681317








  • 1




    An explanation of why it should work would be helpful
    – charlietfl
    Nov 10 at 20:33










  • Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
    – KuchBhi
    Nov 10 at 20:36












  • @KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
    – SakoBu
    Nov 10 at 21:09














  • 1




    An explanation of why it should work would be helpful
    – charlietfl
    Nov 10 at 20:33










  • Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
    – KuchBhi
    Nov 10 at 20:36












  • @KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
    – SakoBu
    Nov 10 at 21:09








1




1




An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33




An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33












Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36






Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36














@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09




@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243031%2fgetting-error-has-been-blocked-by-cors-policy-when-making-api-call%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values