Closed edwardpark closed 9 years ago
Hm. What is this Nom Request Module of which you speak? You mean the Node Request Module?
check out the documentation about including custom headers - https://github.com/request/request#custom-http-headers
ok just tried the github doc but response is not showing anything now which i suppose is a improvement !
Try console.log([error, response, body]);
There has to be information in one of those three.
ok still coming up as a 404
What does the &1001195
at the end of the URL do?
Since this is a GET request, I can visit it in my browser. With the &1001195
it throws a 404; without, it just says I'm missing an API key.
Incidentally, you may want to remove your API key from up there. Don't want any sneaky scrapers to nab it!
took it from the WMTA query instructions
Request URL
https://api.wmata.com/NextBusService.svc/json/jPredictions[?StopID]
lol yeah just trying to get it to work right now
1001195 is a bus stop number
Gotcha. Your URL should look something like this:
https://api.wmata.com/NextBusService.svc/json/jPredictions?StopID=1001195&api_key=[key]
There has to be a ?
before the start of the querystring; &
separates the different items inside it. Also, it looks like you need to actually include "StopID" in the URL. Not very clear on the WMATA site.
The URL above gave me this:
{
"StopName": "7th St + Massachusetts Ave",
"Predictions": [
{
"RouteID": "70",
"DirectionText": "North to Silver Spring Station",
"DirectionNum": "0",
"Minutes": 3,
"VehicleID": "6405",
"TripID": "7725831"
},
{
"RouteID": "70",
"DirectionText": "North to Silver Spring Station",
"DirectionNum": "0",
"Minutes": 8,
"VehicleID": "6362",
"TripID": "7725830"
},
{
"RouteID": "74",
"DirectionText": "North to Convention Center",
"DirectionNum": "0",
"Minutes": 16,
"VehicleID": "3008",
"TripID": "7726506"
},
{
"RouteID": "70",
"DirectionText": "North to Silver Spring Station",
"DirectionNum": "0",
"Minutes": 18,
"VehicleID": "5432",
"TripID": "7725829"
},
{
"RouteID": "74",
"DirectionText": "North to Convention Center",
"DirectionNum": "0",
"Minutes": 33,
"VehicleID": "3006",
"TripID": "7726505"
},
{
"RouteID": "70",
"DirectionText": "North to Silver Spring Station",
"DirectionNum": "0",
"Minutes": 43,
"VehicleID": "6404",
"TripID": "7725827"
},
{
"RouteID": "70",
"DirectionText": "North to Silver Spring Station",
"DirectionNum": "0",
"Minutes": 55,
"VehicleID": "5443",
"TripID": "7725826"
},
{
"RouteID": "74",
"DirectionText": "North to Convention Center",
"DirectionNum": "0",
"Minutes": 75,
"VehicleID": "3008",
"TripID": "7726503"
},
{
"RouteID": "74",
"DirectionText": "North to Convention Center",
"DirectionNum": "0",
"Minutes": 95,
"VehicleID": "3006",
"TripID": "7726502"
}
]
}
Our key keeps getting denied. How did you get that response?
Just pasted it into my browser's address bar! I used the key you put up above.
oh dear lord, ok just figured it out LOL thanks!
we are trying to call a external api in our app.js file and are using the nom request module. however we are confused how to include the api key into the header for it to work.
right now below is the code we are using and have required and install npm request but keep receiving the error "statusCode": 404, "message": "Resource not found"
we have also tried inserting the api_key into the url to no avail.