Last active
February 17, 2022 09:54
-
-
Save dannyBuonocore/b37d8f8f8ba438ba9694d10b1186de0e to your computer and use it in GitHub Desktop.
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
$('#run').click(() => tryCatch(run)); | |
async function run() { | |
const response = await fetch(new Request('https://api.livecoinwatch.com/coins/single'), { | |
method: 'POST', | |
headers: new Headers({ | |
'content-type': 'application/json', | |
'x-api-key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', | |
}), | |
body: JSON.stringify({ | |
currency: 'USD', | |
code: 'ETH', | |
meta: true, | |
}), | |
}); | |
if (!response.ok) { | |
throw new Error(response.statusText); | |
} | |
const json = await response.json(); | |
await Excel.run(async (context) => { | |
const sheet = context.workbook.worksheets.getActiveWorksheet(); | |
sheet.getRange('A1').values = json.name; | |
sheet.getRange('B1').values = json.rate; | |
await context.sync(); | |
}); | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
async function tryCatch(callback) { | |
try { | |
await callback(); | |
} catch (error) { | |
// Note: In a production add-in, you'd want to notify the user through your add-in's UI. | |
console.error(error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment