Skip to content

Instantly share code, notes, and snippets.

@coderbyheart
Last active March 10, 2020 06:29
Show Gist options
  • Save coderbyheart/67d7b9ad2ca0380d887984889f877f84 to your computer and use it in GitHub Desktop.
Save coderbyheart/67d7b9ad2ca0380d887984889f877f84 to your computer and use it in GitHub Desktop.
nrfcloud message downloader
import fetch from 'node-fetch'
import * as querystring from 'querystring'
const f = (pageNextToken, messages = []) => fetch(`https://api.nrfcloud.com/v1/messages?${querystring.stringify({
inclusiveStart: '2019-01-01T00:00:00Z',
exclusiveEnd: new Date().toISOString(),
pageSort: 'desc',
pageLimit: 100,
...(pageNextToken ? { pageNextToken } : {}),
})}`, {
headers: {
'Authorization': 'Bearer <your API key>'
}
})
.then(res => res.json())
.then(({ items, nextStartKey }) => {
messages.push(...items)
if (nextStartKey) {
console.error('.')
return f(nextStartKey, messages)
}
return messages
})
f()
.then(messages => {
console.log(JSON.stringify(messages))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment