Skip to content

Instantly share code, notes, and snippets.

@jvns
Created August 18, 2020 14:01
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jvns/738eda48bff8c4dd2a5e349b8df7c7a8 to your computer and use it in GitHub Desktop.
Save jvns/738eda48bff8c4dd2a5e349b8df7c7a8 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
async function run() {
let username = "YOUR USERNAME HERE";
let password = "YOUR APP PASSWORD";
let authBasic = new Buffer(username + ':' + password).toString('base64');
let session = await (await fetch('https://jmap.fastmail.com/.well-known/jmap', {
headers: {
"Authorization": "Basic " + authBasic
}
})).json();
let accountId = session['primaryAccounts']['urn:ietf:params:jmap:mail'];
let query = {
"using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ],
"methodCalls": [[ "Mailbox/get", {
"accountId": accountId,
"ids": null
}, "0" ]]
}
let data = await (await fetch('https://jmap.fastmail.com/api/', {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + authBasic
},
body: JSON.stringify(query)
})).json();
console.log(data.methodResponses[0][1])
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment