- Notifications
You must be signed in to change notification settings - Fork21
Official JavaScript client for the YNAB API
License
ynab/ynab-sdk-js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Please read theYNAB API documentation for an overview of using the API and a complete list of available resources.
This client is generated using theOpenAPI Generator.
First, install the module with npm:
npm install ynab
Then, depending upon your usage context, add a reference to it:
const ynab = require("ynab");import * as ynab from "ynab";The API supportsCross Origin Resource Sharing (CORS) for asynchronous browser requests from any origin.
Thedist/browser/ynab.js file (located in node_modules/ynab after installation) is specifically built to run in a browser / window context and exportsynab variable to global namespace. No other dependencies are needed.
<script src="ynab.js" async></script>...<script> // This assignment is not necessary but demonstrates that // once the library is loaded, the global 'ynab' object will be available. var ynab = window.ynab;</script>A simple way to load the library in a browser is by using theunpkg CDN, which is a"fast, global content delivery network for everything on npm". To use it, include a script tag like this in your file:
<script src="https://unpkg.com/ynab@latest/dist/browser/ynab.js" async></script>Using the "latest" tag will result in a 302 redirect to the latest version tag so it is highly recommended to use a specific version tag such ashttps://unpkg.com/ynab@1.5.0/dist/browser/ynab.js to avoid this redirect.
To use this client, you mustobtain an access token fromtheAccount Settings area of the YNAB webapplication.
constynab=require("ynab");constaccessToken="b43439eaafe2_this_is_fake_b43439eaafe2";constynabAPI=newynab.API(accessToken);(asyncfunction(){constbudgetsResponse=awaitynabAPI.budgets.getBudgets();constbudgets=budgetsResponse.data.budgets;for(letbudgetofbudgets){console.log(`Budget Name:${budget.name}`);}})();
If a response is returned with a code >= 300, instead of returning the response,the response will be thrown as an error to be caught.
constynab=require("ynab");constaccessToken="invalid_token";constynabAPI=newynab.API(accessToken);constbudgetsResponse=ynabAPI.budgets.getBudgets().then(budgetsResponse=>{// Won't get here because an error will be thrown}).catch(e=>{console.log(e);// {// error: {// id: "401",// name: "unauthorized",// detail: "Unauthorized"// }// }});
The API enforcesRate Limiting.
If the rate limit is exceeded, a429Error Response will be returned from the API which will result in anerror being thrown in this library.
See theexamplesfolder for example usage scenarios.
The following methods are available in this library.
There are several utilities available on theutils export to make workingwithISO dates and milliunits a biteasier.
// Returns the current month (system timezone) in ISO 8601 format (i.e. '2015-12-01')utils.getCurrentMonthInISOFormat(): string;// Returns the current date (system timezone) in ISO 8601 format (i.e. '2015-12-15')utils.getCurrentDateInISOFormat(): string;// Converts an ISO 8601 formatted string to a JS date objectutils.convertFromISODateString(isoDateString: string):Date;// Converts a milliunits amount to a currency amountutils.convertMilliUnitsToCurrencyAmount(milliunits: number,currencyDecimalDigits: number): number;
The version of this client is defined in thepackage.json file and followssemantic versioning. The version of this client is maintained independently and does not align with the the version of YNAB API itself (which is defined in theOpenAPI spec). To determine which spec version of the YNAB API was used when generating this client you can refer to the "description" field in thepackage.json file.
Copyright (c) 2022 You Need A Budget, LLC
Licensed under the Apache-2.0 license
About
Official JavaScript client for the YNAB API
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Contributors10
Uh oh!
There was an error while loading.Please reload this page.