Skip to content

Instantly share code, notes, and snippets.

@AriesTriputranto99
Forked from jvns/fastmail-jmap-quickstart.js
Last active December 21, 2024 07:24
Show Gist options
  • Save AriesTriputranto99/8efac53f0f7481c0ceacbe680650ff97 to your computer and use it in GitHub Desktop.
Save AriesTriputranto99/8efac53f0f7481c0ceacbe680650ff97 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
async function run(*) {
let username = "AriesTriputranto";
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