Socket
Socket
Sign inDemoInstall

ynab

Package Overview
Dependencies
7
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ynab

YNAB API Javascript (Node) Library


Version published
Maintainers
1
Install size
785 kB
Created

Readme

Source

YNAB API Javascript (Node) Library

NPM Package code style: prettier

The YNAB API JavaScript library provides access to the YNAB API from applications written in Node.js / JavaScript.

Please read the YNAB API documentation for an overview of using the API and a complete list of the available resources.

Installation

npm install ynab

Usage

To use this client, you must obtain an access token from the My Account area of the YNAB web application.

const ynabApi = require("ynab");
const accessToken = "bf0cbb14b4330e9d5f4312a646eb0115b80a169ad1425d3de12e66a389eaafe2";
const ynab = new ynabApi(accessToken);

async function listBudgets(){
  const budgetsResponse = await ynab.budgets.getBudgets();
  const budgets = budgetsResponse.data.budgets;
  for(let budget of budgets) {
    console.log(`Budget Name: ${budget.name}`);
  }
}

listBudgets();

Error Handling

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.

const ynabApi = require("ynab-sdk-js");
const accessToken = "invalid_token";
const ynab = new ynabApi(accessToken);

const budgetsResponse = ynab.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"
    //   }
    // }
  });

Utilities

There are several utilities available on the ynab.utils object to make working with ISO dates and milliunits a bit easier.

/**
  * Returns the current month (system timezone) in ISO 8601 format (i.e. '2015-12-01')
  */
getCurrentMonthInISOFormat(): string;

/**
  * Converts an ISO 8601 formatted string to a JS date object
  * @param {string} isoDate - An ISO 8601 formatted date (i.e. '2015-12-30').  This date is assumed to be in UTC timezone
  */
convertFromISODateString(isoDateString: string): Date;

/**
 * Converts a milliunits amount to a currency amount
 * @param milliunits - The milliunits amount (i.e. 293294)
 * @param currencyDecimalDigits - The number of decimals in the currency (i.e. 2 for USD)
 */
convertMilliUnitsToCurrencyAmount(milliunits: number, currencyDecimalDigits: number): number;

Examples

See the examples folder for example usage scenarios.

Development

To build and compile:

npm install
npm run build

To run tests:

npm test

License

Copyright (c) 2018 You Need A Budget, LLC

Licensed under the Apache-2.0 license

Keywords

FAQs

Last updated on 08 Jan 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc