API URL Help needed - javascript

I'm looking for some help and wasn't sure where to go for it. Was hoping someone more knowledgeable could give me some quick help. I'm trying to use an Api to get Hearthstone card game data and I have the end point which is
"https://omgvamp-hearthstone-v1.p.mashape.com/cards"
2:28 pm
And I have my API key which is "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" And I can't figure out how to string it all together into a single URL that will return data.
I've been trying things along the lines of "https://omgvamp-hearthstone-v1.p.mashape.com/cards?x-mashape-key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
But nothing's giving, any ideas if anyone has some free time?

You need to have x-mashape-key in your request headers rather than in the query string, according to their API take a look at the CURL request:
https://market.mashape.com/omgvamp/hearthstone
Try going here: http://requestmaker.com/ filling in the URL leaving out the last part of x-mashape-key and add a request header with key/value of x-mashape-key:XXXXXXXXXXXXXXXX then hit request and you should get a response.

Related

Can you use a POST to GET data?

A company is asking me to do an Angular assignment. They provide the following instructions, but the API URL doesn't work:
Create a single page angular application and use the following API to retrieve sports results and sort into a table of results that are displayed. Each sport result contains several data and always includes the publication time.
Method: POST
Content-Type: application/json
Url: https://ancient-wood-1161.getsandbox.com:443/results
Tasks:
-Display the sports results in reverse chronological order on the page.
-Add a filter to the page to display only certain types or events (e.g. f1Results)
-How can you confirm the code works?
-Bonus: Implement the rest call asynchronously
You can click the URL https://ancient-wood-1161.getsandbox.com:443/results right now and see that it doesn't work - it returns {"errors":[{"message":"Error processing request"}]} and in Angular it gives me a standard CORS error.
I asked the company to please send a working URL and/or update the API to accept requests from everywhere. Their response was:
*guy's name* confirmed it worked. It is a post and the content type is json.
Can you use a POST request to GET data?
Absolutely. Take for example your avg Login Request that returns an access token for instance. It is going to be a POST as POST also has a bit more security than GET given that the payload is in the body rather than the URL string.
As for their excuse of it not working, try it in postman and see if the same issue still occurs. If it still does then ask them where did they test their API as if it is on prem then no duh the CORS would work. It is most likely not a company you would want to work for.
Yes, you can. On some cases it may be necessary, since GET doesn't take a body while POST does. So it can get you around things like URL length limits.

Return URL Whenever a Client Requests a Page

I'm pretty new to JavaScript and I'm trying to send data from an ESP8266 to my Github Pages through simple URL data. To send data, the ESP will just try to connect to "mygithubpages.com?DATA." On the server side, I'm trying to get the DATA portion of that URL and use it. Hopefully, this is clear but if not I'd be glad to clarify. Thanks in advance!
As far as I understand your goal is to retrieve GET params of your page's url. If so, then window.location.search will contain ?DATA in your case and if your goal is to get only DATA then use window.location.search.substr(1)

How do I call 2 endpoints with one proxy in Apigee?

Hi I am trying to call two different endpoints via one proxy here.
1st endpoint: basically its the java-script I coded into the .js file
2nd endpoint: this is an endpoint where I have to send the request to a third-party URL and get the response and return.
So I want to send a parameter in my query string like this:
http://[url to my apigee proxy]/endpoint?stub=true
If this is the url then it should go to my JavaScript code. If this is the url:
http://[url to my apigee proxy]/endpoint?stub=false
Then it should go to a third party url. I have already looked and tried to implement this;
http://stackoverflow.com/questions/22783986/one-api-proxy-calling-two-different-target-endpoints but it's not working for me.
Any suggestions will be appreciated.
Your missing target endpoints. Please add target endpoint xml. Also take look at samples which will help you along side documentation.

Using Google Spreadsheet as JSON file using tabletop to datatables returns error

I'm a relative newbie when it comes to coding, especially javascript. I currently am trying to populate a table from a google spreadsheet, which will update when the spreadsheet is.
I followed this tutorial word for word (basically all you need to do is replace the key with your own to specify your spreadsheet, and make sure its both published and public, which I've done)
http://dataforradicals.com/the-absurdly-illustrated-guide-to-sortable-searchable-online-data-tables/
I just get a bad request 400 error referring to my spreadsheet. If I visit the spreadsheet generated directly I just get the words...
"Invalid query parameter value for sq."
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&sq=&callback=Tabletop.callbacks.tt140241226993949106
I can visit my spreadsheet with the link I was given when I published it here..
[maximum links reached but the structure is different]
As you can see the domain structure is different. I fear that "Tabletop to Datatables" is adding an outdated url to the start of that link but can't find where it actually applies it.
The only reason I would think thats not happening is because the example in the tutorial still works! And the link it refers to is the old style URL too
I'm baffled, please help if you can. All suggestions appreciated
The query string includes a parameter without a value, &sq=.
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&sq=&callback=Tabletop.callbacks.tt140241226993949106
^^^^
Try this, with that parameter completely removed...
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&callback=Tabletop.callbacks.tt140241226993949106
There is an updated version of this project. Any necessary updates are included here:
https://github.com/scottpham/tabletop-to-datatables
Try with the updated versions of all js libraries.
Check the link and remove the extra string after pub. That part of link is not necessary and may cause issues.
According to google:
The 400 Bad Request error is an HTTP status code that means that the request you sent to the website server, often something simple like a request to load a web page, was somehow incorrect or corrupted and the server couldn't understand it.
Good luck

Weatherbug REST JSON

I have a solid understanding of HTML and javascript. I have no experience with JSON. I would like to get the data from the URL http://i.wxbug.net/REST/Direct/GetUv.ashx?zip=21044&api_key=vxwdyz3evgtvuv9d5e53sckc and display it on a webpage. I have looked around for a simple tutorial that explains how to retrieve JSON data from a URL without prevail. Can someone point me in the right direction?
If your page is in different domain, you will encounter the "...not allowed by Access-Control-Allow-Origin" error when you use javascript to access it. However, you could make a proxy page in the server side, fetch the data and then output data.
And then, you could get the data, for example, if you use jQuery, it is very easy like:
$.getJSON(your_proxy_page_url,function(data) {
console.log(data);
});
You could also try to take look at this post, maybe it can help you out:
http://docs.jquery.com/Release:jQuery_1.2/Ajax#Cross-Domain_getScript

Categories

Resources