Search for stops
Here we will be using the Search stops endpoint to search for stops using keywords and filters.
- JS Web
- Node
- Python
- curl
// Set the access token
const accessToken = 'YOUR_ACCESS_TOKEN'
// Headers for the request
const headers = new Headers()
headers.append('Accept', 'application/json')
headers.append('Authorization', `Bearer ${accessToken}`)
async function searchStops() {
const keyword = 'london'
const filter = 'address.countryCode = "GB"'
// The filter string must be URL-encoded when passed as a query parameter.
const url = `https://api.spoke.com/v1/stops:search?keyword=${encodeURIComponent(keyword)}&filter=${encodeURIComponent(filter)}`
// Perform the request with GET method
const response = await fetch(url, {
method: 'GET',
headers: headers,
})
// The response will return an object containing the matching stops
const data = await response.json()
console.log(data)
}
// We are using the axios library here to make requests from Node
const axios = require('axios')
const accessToken = 'YOUR_ACCESS_TOKEN'
async function searchStops() {
const keyword = 'london'
const filter = 'address.countryCode = "GB"'
try {
const response = await axios.get('https://api.spoke.com/v1/stops:search', {
params: {
keyword,
filter,
},
headers: {
Accept: 'application/json',
Authorization: `Bearer ${accessToken}`,
},
})
// The response data will contain the matching stops
console.log(response.data)
} catch (error) {
console.error(
'Error searching stops:',
error.response ? error.response.data : error.message,
)
}
}
# We are using the requests library here to make requests from Python
import requests
# Set the access token
access_token = "YOUR_ACCESS_TOKEN"
# Search parameters
params = {
"keyword": "london",
"filter": 'address.countryCode = "GB"'
}
# Headers
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {access_token}"
}
# Perform the request with GET method
response = requests.get(
"https://api.spoke.com/v1/stops:search",
params=params,
headers=headers
)
# The response will return an object containing the matching stops
search_results = response.json()
print(search_results)
curl -X GET "https://api.spoke.com/v1/stops:search?keyword=london&filter=address.countryCode%20%3D%20%22GB%22%" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Accept: application/json"