const request = require('request-promise');
// this is the root url of all the dashcam api requests
const dashcamApi = `https://hivemapper.com/api/dashcam/v1`;
// take your username and API key delimited by a `:`
const credentials = `${USERNAME}:${API_KEY}`;
const encoded = Buffer.from(credentials).toString('base64');
// and append it to a string `Basic `
const authorization = `Basic ${encoded}`;
// this is your authorization header
const headers = { authorization };
* Helper to make an api call to fetch assets contained by
* box on a mercator-projected earth
* contentSince - specify a time filter to return data that was collected
* greater than to equal to some date
* dates are typically in YYYY-MM-DD format, but you can
* use any valid JS-compatible ISO 9601 timestamp or seconds since epoch
* lon - longitude in degrees of box center
* lat - latitude in degrees of box center
* radius (meters) describes a circle centered at these coordinates
* (we'll draw a box around it and that's our query)
async function makeConsumeBoxApiCall(contentSince, lon, lat, radius) {
const apiCall = `consume/box`;
const uri = [dashcamApi, contentSince, apiCall, lon, lat, radius].join('/');
const response = await request({
const results = await makeConsumeBoxApiCall(
// { "assets": [url1, url2, url3, ...] }
// urls point to images and will expire in 24 hours