The YNAB API is REST based, uses the JSON data format and is secured with HTTPS. You can use it to build a personal application to interact with your own budget or build an application that any other YNABer can authorize and use. Be sure to check out what other YNABers have built in the Works with YNAB section and let us know when you build something yourself!
If you want to start working with the API to build something more substantial, you might want to check out our YNAB API Starter Kit which is a simple, but functional web application that uses the API.
Personal Access Tokens are access tokens created by an account owner and are intended to be used only by that same account owner. They should not be shared and are intended for individual usage scenarios. They are a convenient way to obtain an access token without having to use a full OAuth authentication flow. If you are an individual developer and want to simply access your own account through the API, Personal Access Tokens are the best choice.
To obtain a Personal Access Token, sign in to your account, go to "Account Settings", scroll down and navigate to "Developer Settings" section. From the Developer Settings page, click "New Token" under the Personal Access Tokens section, enter your password and you will be presented with a new Personal Access Token. You will not be able to retrieve the token later so you should store it in a safe place. This new token will not expire but can be revoked at any time from this same screen.
OAuth is a secure way for a third-party application to obtain delegated but limited permissions to a user account and is appropriate for use in applications that need to gain limited authorized permissions to accounts they do not own. If you are developing an application that uses the API and want other users to be able to use your application, OAuth is the only option for obtaining access tokens for other users.
When an OAuth application is created, it will be placed in Restricted Mode initially. This means the application will be limited to obtaining 25 access tokens for users other than the OAuth application owner. Once this limit is reached, a message will be placed on the Authorization screen and new authorizations will be prohibited.
To have Restricted Mode removed, you must send a request to a...@ynab.com. We will review your OAuth application to ensure it abides by the API Terms of Service and the OAuth Application Requirements. Once we review the application and confirm adherence to our policies, we will remove Restricted Mode.
To create an OAuth Application, sign in to your account, go to "Account Settings", scroll down and navigate to "Developer Settings" section. From the Developer Settings page, click "New Application" under the OAuth Applications section. Here, you specify the details of your application and save it. After saving, you will see the details of the new application, including the Client ID and the Client Secret which are referenced in the instructions below.
After creating the application, you are then able to use one of the supported grant types to obtain a valid access token. The YNAB API supports two OAuth grant types: Implicit Grant and Authorization Code Grant.
The Implicit Grant type, also informally known as the "client-side flow", should be used in scenarios where the application Secret cannot be kept private. The application Secret should never be visible or accessible by a client! If you are requesting an access token directly from a browser or other client that is not secure (i.e. mobile app) this is the flow you should use. This grant type does not support refresh tokens so once the access token expires 2 hours after it was granted, the user must be prompted again to authorize your application.
The Authorization Code Grant type, also informally known as the "server-side flow", is intended for server-side applications, where the application Secret can be protected. If you are requesting an access token from a server application that is private and under your control, this grant type can be used. This grant type supports refresh tokens so once the access token expires 2 hours after it was granted, the application can request a new access token without having to prompt the user to authorize again.
When an OAuth application is requesting authorization, a scope parameter with a value of read-only can be passed to request read-only access to a budget. For example: _id=[CLIENT_ID]&redirect_uri=[REDIRECT_URI]&response_type=token&scope=read-only. If an access token issued with the read-only scope is used when requesting an endpoint that modifies the budget (POST, PATCH, etc.) a 403 Forbidden response will be issued. If you do not need write access to a budget, please use the read-only scope.
An optional, but recommended, state parameter can also be supplied to prevent Cross Site Request Forgery (XRSF) attacks. If specified, the same value will be returned to the [REDIRECT_URI] as a state parameter. For example: if you included parameter state=4cac8f43 in the authorization URI, when the user is redirected to [REDIRECT_URI], the URL would contain that same value in a state parameter. The value of state should be unique for each request.
Once you have obtained an access token, you must use HTTP Bearer Authentication, as defined in RFC6750, to authenticate when sending requests to the API. We support Authorization Request Header and URI Query Parameter as means to pass an access token.
Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. We support Cross-Origin Resource Sharing (CORS) which allows you to use the API directly from a web application.
TLS (a.k.a. SSL or HTTPS) is enforced on all requests to ensure communication from your client to our endpoint is encrypted, end-to-end. You must obtain an access token and provide it with each request. An access token is tied directly to a YNAB account but can be independently revoked.
Some endpoints support Delta Requests, where you can request to receive only what has changed since the last response. It is highly recommended to use this feature as it reduces load on our servers as well as makes processing responses more efficient.
Errors and exceptions will sometimes happen. You might experience a connection problem between your app and the YNAB API or a complete outage. You should always anticipate that errors or exceptions may occur and build in accommodations for them in your application.
You should use the most specific request possible to avoid large responses which are taxing on the API server and slower for your app to consume and process. For example, if you want to retrieve the balance for a particular category, you should request that single category from /budgets/budget_id/categories/category_id rather than requesting all categories.
Successful responses will return wrapper object with a data property that will contain the resource data. The name of the object inside of the data property will correspond to the requested resource.
Resources supporting delta requests return a server_knowledge number in the response. This number can then be passed in as the last_knowledge_of_server query parameter. Then, only the data that has changed since the last request will be included in the response.
The limit is reset every clock hour. So, if an access token is used at 12:30 PM and for 199 more requests up to 12:45 PM and then hits the limit, any additional requests will be forbidden until 1:00 PM. At 1:00 PM you would have the full 200 requests allowed again, until 2:00 PM.
You can check how many requests you have remaining by referencing the X-Rate-Limit response header. The value of this header is in the format: X/200, X being the number of requests already made and 200 being the limit. For example, if your application has already made 35 requests, the next response will look like this:
The JavaScript library is available via npm and the source and documentation is located on GitHub. This library can be used server-side (Node.js) or client-side (web browser) since we support Cross-Origin Resource Sharing (CORS).
In addition to the above terms, OAuth Applications must adhere to these requirements:
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.
A simple way to load the library in a browser is by using the unpkg 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:
b37509886e