I have a little experience with HTML and Javascript coding, but have never used an API. I want to start learning with the Halo 5 API and make something basic. I’ve been trying to do something as simple as having my emblem image show up on a custom website, but it doesn’t seem to be working, and honestly I have no idea what I’m doing.
This is the code I’m using (obviously with the correct subscription key), and when I run it I get the error alert. I’m subscribed with the H5 API site as a developer. Any help?
You cannot use the API directly using JavaScript because of CORS. A quick search on stack overflow regarding JavaScript, API, and CORS should give you more info. If you want to use JavaScript, you’d have to set up your own web server to complete the requests then pass the info on to the client.
> 2767837270998187;2:
> You cannot use the API directly using JavaScript because of CORS. A quick search on stack overflow regarding JavaScript, API, and CORS should give you more info. If you want to use JavaScript, you’d have to set up your own web server to complete the requests then pass the info on to the client.
Can you direct me to any resources where I can learn how to do this?
> 2533274798866216;4:
> > 2767837270998187;2:
> > You cannot use the API directly using JavaScript because of CORS. A quick search on stack overflow regarding JavaScript, API, and CORS should give you more info. If you want to use JavaScript, you’d have to set up your own web server to complete the requests then pass the info on to the client.
>
>
> Can you direct me to any resources where I can learn how to do this?
> 2533274798866216;4:
> > 2767837270998187;2:
> > You cannot use the API directly using JavaScript because of CORS. A quick search on stack overflow regarding JavaScript, API, and CORS should give you more info. If you want to use JavaScript, you’d have to set up your own web server to complete the requests then pass the info on to the client.
>
>
> Can you direct me to any resources where I can learn how to do this?
I don’t have a specific example to give you but the internet is full of them. Here is an article explaining cors in more detail:
The section labeled “Adding CORS support to the server” is why we can’t use javascript to directly connect with the halo api. 343 has not enabled (and most likely won’t) enable CORS on their end because they would have to whitelist each individual web-app. That could be done if each of us when we register tell them what URL to expect from us. However, for the time being, it is not supported.
As others have mentioned in this forum, you can set up as complicated or simple webserver to act as a proxy as you’d like. This handles retrieving info from the API and pushing it to your webapp.
For my particular application, I set up a free webserver on https://www.openshift.com. From there you can choose whichever technology you are most comfortable with. .Net, Java, Node, etc.
I hope this helps. Let me know if you have any more specific questions. I’d be more than willing to help out. I would say give a shot at building a simple webserver to connect with the Halo API first.