Im learning to work with APIs. Im trying to make an api call like :
curl -X POST https://api.locu.com/v2/venue/search -d '{
"api_key" : "f165c0e560d0700288c2f70cf6b26e0c2de0348f",
"fields" : [ "name", "location", "contact" ],
"venue_queries" : [
{
"name" : "bistro central parc"
}
]
}'
this works with curl but I am wanting to make the call without cURL. I will be doing this using request from node, right now however I just want to use postman to make the call. I have tried:
https://api.locu.com/v2/venue/search?api_key={myAPIKey}&fields=["name","location","contact"]&venue_queries=[{name="bistro%20central%20parc"}]
however I get a 405 method not allowed. Im obviously looking at this the wrong way. Is this not the proper way to format the http request?
In javascript would this look like:
var request = require('request');
request('https://api.locu.com/v2/venue/search?api_key={myAPIKey}&fields=["name","location","contact"]&venue_queries=[{name="bistro%20central%20parc"}]', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Print the google web page.
}
})
or would there be a better way to structure the options?
There certainly is, take a look at the docs on the qs object you can pass in:
qs - object containing querystring values to be appended to the uri
var request = require('request');
var queryObject = { field1:'test1', field2:'test2' };
request.get({url: url, qs: queryObject})
.then(function(response){
// do stuff
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.