Last active
March 10, 2020 06:29
-
-
Save coderbyheart/67d7b9ad2ca0380d887984889f877f84 to your computer and use it in GitHub Desktop.
nrfcloud message downloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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