Socket
Socket
Sign inDemoInstall

ynab

Package Overview
Dependencies
7
Maintainers
3
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ynab

YNAB API Javascript (Node) Library


Version published
Weekly downloads
688
decreased by-19.15%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

YNAB API JavaScript Library

Build Status npm version

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

This client is generated using the Swagger Code Generator.

Installation

First, install the module with npm (or yarn):

npm install ynab

Then, depending upon your usage context, add a reference to it:

CommonJS / Node

const ynab = require("ynab");

ESM / TypeScript

import * as ynab from "ynab";

Browser

The API supports Cross Origin Resource Sharing (CORS) for asynchronous browser requests from any origin.

The dist/browser/ynab.js file (located in node_modules/ynab after installation) is specifically built to run in a browser / window context and exports ynab variable to global namespace. No other dependencies are needed.

<script src="ynab.js" async></script>
...
<script>
  var ynab = window.ynab;
</script>

Usage

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

const accessToken = "b43439eaafe2_this_is_fake_b43439eaafe2";
const ynabAPI = new ynab.API(accessToken);

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

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 ynab = require("ynab");
const accessToken = "invalid_token";
const ynabAPI = new ynab.API(accessToken);

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

Examples

See the examples folder for example usage scenarios.

Methods

The following methods are available in this library. For more details on parameters and usage, the TypeScript declaration file can be referenced.

MethodDescription
Userbudgets.get_user()Returns authenticated user information
Budgetsbudgets.get_budgets()Returns budgets list with summary information
budgets.get_budget_by_id(id)Returns a single budget with all related entities
budgets.get_budget_settings_by_id(id)Returns settings for a budget
Accountsaccounts.get_accounts(budget_id)Returns all accounts
accounts.get_account_by_id(budget_id, id)Returns a single account
Categoriescategories.get_categories(budget_id)Returns all categories grouped by category group.
categories.get_category_by_id(budget_id, id)Returns a single category
Payeespayees.get_payees(budget_id)Returns all payees
payees.get_payee_by_id(budget_id, id)Returns single payee
Payee Locationspayee_locations.get_payee_locations(budget_id)Returns all payee locations
payee_locations.get_payee_location_by_id(budget_id, id)Returns a single payee location
payee_locations.get_payee_locations_by_payee(budget_id, id)Returns all payee locations for the specified payee
Monthsmonths.get_budget_months(budget_id)Returns all budget months
months.get_budget_month(budget_id, month)Returns a single budget month
Transactionstransactions.get_transactions(budget_id)Returns budget transactions
transactions.get_transactions_by_account(budget_id, id)Returns all transactions for a specified account
transactions.get_transactions_by_category(budget_id, id)Returns all transactions for a specified category
transactions.get_transactions_by_id(budget_id, id)Returns a single transaction
transactions.update_transaction(budget_id, id, transaction)Updates a transaction
transactions.create_transaction(budget_id, transaction)Creates a new transaction
transactions.bulk_create_transactions(budget_id, transactions)Creates multiple transactions
Scheduled Transactionsscheduled_transactions.get_scheduled_transactions(budget_id)Returns all scheduled transactions
scheduled_transactions.get_scheduled_transaction_by_id(budget_id, id)Returns a single scheduled transaction
                                                            |

Utilities

There are several utilities available on the utils export 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;
// Returns the current date (system timezone) in ISO 8601 format (i.e. '2015-12-15')
getCurrentDateInISOFormat(): string;
// Converts an ISO 8601 formatted string to a JS date object
convertFromISODateString(isoDateString: string): Date;
// Converts a milliunits amount to a currency amount
convertMilliUnitsToCurrencyAmount(milliunits: number, currencyDecimalDigits: number): number;

Development

  • Install dependencies: npm install
  • Generate latest client based on swagger spec: npm run generate
  • Run tests: npm test
  • Publish to npm: npm run release

License

Copyright (c) 2018 You Need A Budget, LLC

Licensed under the Apache-2.0 license

Keywords

FAQs

Last updated on 18 Jul 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