Coder Social home page Coder Social logo

waterkip / ynab-sdk-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ynab/ynab-sdk-js

0.0 2.0 0.0 515 KB

YNAB API Javascript Library

Home Page: https://api.youneedabudget.com

License: Apache License 2.0

JavaScript 1.37% HTML 5.88% TypeScript 92.75%

ynab-sdk-js's Introduction

YNAB API JavaScript Library

Build Status NPM Package code style: prettier

NOTE: The YNAB API is currently only available to Early Access users. If you are interested in requesting access before the API is generally available, please fill out this form.

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.

Method Description
User budgets.getUser() Returns authenticated user information
Budgets budgets.getBudgets() Returns budgets list with summary information
budgets.getBudgetById(id) Returns a single budget with all related entities
Accounts accounts.getAccounts(budgetId) Returns all accounts
accounts.getAccountById(budgetId, id) Returns a single account
Categories categories.getCategories(budgetId) Returns all categories grouped by category group.
categories.getCategoryById(budgetId, id) Returns a single category
Payees payees.getPayees(budgetId) Returns all payees
payees.getPayeeById(budgetId, id) Returns single payee
Payee Locations payeeLocations.getPayeeLocations(budgetId) Returns all payee locations
payeeLocations.getPayeeLocationById(budgetId, id) Returns a single payee location
payeeLocations.getPayeeLocationsByPayee(budgetId, id) Returns all payee locations for the specified payee
Months months.getBudgetMonths(budgetId) Returns all budget months
months.getBudgetMonth(budgetId, month) Returns a single budget month
Transactions transactions.getTransactions(budgetId) Returns budget transactions
transactions.getTransactionsByAccount(budgetId, id) Returns all transactions for a specified account
transactions.getTransactionsByCategory(budgetId, id) Returns all transactions for a specified category
transactions.getTransactionsById(budgetId, id) Returns a single transaction
transactions.updateTransaction(budgetId, id, transaction) Updates a transaction
transactions.createTransaction(budgetId, transaction) Creates a new transaction
transactions.bulkCreateTransactions(budgetId, transactions) Creates multiple transactions
Scheduled Transactions scheduledTransactions.getScheduledTransactions(budgetId) Returns all scheduled transactions
scheduledTransactions.getScheduledTransactionById(budgetId, 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

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

ynab-sdk-js's People

Contributors

bradymholt avatar taytay avatar shama avatar

Watchers

James Cloos avatar Wesley Schwengle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.