UNPKG

ynab

Version:

Official JavaScript client for the YNAB API. API documentation available at https://api.ynab.com. Generated from server specification version 1.85.0

558 lines (557 loc) 30.3 kB
"use strict"; /* tslint:disable */ /* eslint-disable */ /** * YNAB API Endpoints * 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. API Documentation is at https://api.ynab.com * * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.GetTransactionsByPayeeTypeEnum = exports.GetTransactionsByMonthTypeEnum = exports.GetTransactionsByCategoryTypeEnum = exports.GetTransactionsByAccountTypeEnum = exports.GetTransactionsTypeEnum = exports.TransactionsApi = void 0; const runtime = __importStar(require("../runtime")); const index_1 = require("../models/index"); /** * */ class TransactionsApi extends runtime.BaseAPI { /** * Creates a single transaction or multiple transactions. If you provide a body containing a `transaction` object, a single transaction will be created and if you provide a body containing a `transactions` array, multiple transactions will be created. Scheduled transactions (transactions with a future date) cannot be created on this endpoint. * Create a single transaction or multiple transactions */ async createTransactionRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling createTransaction.'); } if (requestParameters.data === null || requestParameters.data === undefined) { throw new runtime.RequiredError('data', 'Required parameter requestParameters.data was null or undefined when calling createTransaction.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/transactions`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))), method: 'POST', headers: headerParameters, query: queryParameters, body: (0, index_1.PostTransactionsWrapperToJSON)(requestParameters.data), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.SaveTransactionsResponseFromJSON)(jsonValue)); } /** * Creates a single transaction or multiple transactions. If you provide a body containing a `transaction` object, a single transaction will be created and if you provide a body containing a `transactions` array, multiple transactions will be created. Scheduled transactions (transactions with a future date) cannot be created on this endpoint. * Create a single transaction or multiple transactions */ async createTransaction(planId, data, initOverrides) { const response = await this.createTransactionRaw({ planId: planId, data: data }, initOverrides); return await response.value(); } /** * Deletes a transaction * Delete a transaction */ async deleteTransactionRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling deleteTransaction.'); } if (requestParameters.transactionId === null || requestParameters.transactionId === undefined) { throw new runtime.RequiredError('transactionId', 'Required parameter requestParameters.transactionId was null or undefined when calling deleteTransaction.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/transactions/{transaction_id}`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"transaction_id"}}`, encodeURIComponent(String(requestParameters.transactionId))), method: 'DELETE', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.TransactionResponseFromJSON)(jsonValue)); } /** * Deletes a transaction * Delete a transaction */ async deleteTransaction(planId, transactionId, initOverrides) { const response = await this.deleteTransactionRaw({ planId: planId, transactionId: transactionId }, initOverrides); return await response.value(); } /** * Returns a single transaction * Get a transaction */ async getTransactionByIdRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getTransactionById.'); } if (requestParameters.transactionId === null || requestParameters.transactionId === undefined) { throw new runtime.RequiredError('transactionId', 'Required parameter requestParameters.transactionId was null or undefined when calling getTransactionById.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/transactions/{transaction_id}`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"transaction_id"}}`, encodeURIComponent(String(requestParameters.transactionId))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.TransactionResponseFromJSON)(jsonValue)); } /** * Returns a single transaction * Get a transaction */ async getTransactionById(planId, transactionId, initOverrides) { const response = await this.getTransactionByIdRaw({ planId: planId, transactionId: transactionId }, initOverrides); return await response.value(); } /** * Returns plan transactions, excluding any pending transactions * Get transactions */ async getTransactionsRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getTransactions.'); } const queryParameters = {}; if (requestParameters.sinceDate !== undefined) { queryParameters['since_date'] = requestParameters.sinceDate; } if (requestParameters.untilDate !== undefined) { queryParameters['until_date'] = requestParameters.untilDate; } if (requestParameters.type !== undefined) { queryParameters['type'] = requestParameters.type; } if (requestParameters.lastKnowledgeOfServer !== undefined) { queryParameters['last_knowledge_of_server'] = requestParameters.lastKnowledgeOfServer; } const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/transactions`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.TransactionsResponseFromJSON)(jsonValue)); } /** * Returns plan transactions, excluding any pending transactions * Get transactions */ async getTransactions(planId, sinceDate, untilDate, type, lastKnowledgeOfServer, initOverrides) { const response = await this.getTransactionsRaw({ planId: planId, sinceDate: sinceDate, untilDate: untilDate, type: type, lastKnowledgeOfServer: lastKnowledgeOfServer }, initOverrides); return await response.value(); } /** * Returns all transactions for a specified account, excluding any pending transactions * Get account transactions */ async getTransactionsByAccountRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getTransactionsByAccount.'); } if (requestParameters.accountId === null || requestParameters.accountId === undefined) { throw new runtime.RequiredError('accountId', 'Required parameter requestParameters.accountId was null or undefined when calling getTransactionsByAccount.'); } const queryParameters = {}; if (requestParameters.sinceDate !== undefined) { queryParameters['since_date'] = requestParameters.sinceDate; } if (requestParameters.untilDate !== undefined) { queryParameters['until_date'] = requestParameters.untilDate; } if (requestParameters.type !== undefined) { queryParameters['type'] = requestParameters.type; } if (requestParameters.lastKnowledgeOfServer !== undefined) { queryParameters['last_knowledge_of_server'] = requestParameters.lastKnowledgeOfServer; } const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/accounts/{account_id}/transactions`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"account_id"}}`, encodeURIComponent(String(requestParameters.accountId))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.TransactionsResponseFromJSON)(jsonValue)); } /** * Returns all transactions for a specified account, excluding any pending transactions * Get account transactions */ async getTransactionsByAccount(planId, accountId, sinceDate, untilDate, type, lastKnowledgeOfServer, initOverrides) { const response = await this.getTransactionsByAccountRaw({ planId: planId, accountId: accountId, sinceDate: sinceDate, untilDate: untilDate, type: type, lastKnowledgeOfServer: lastKnowledgeOfServer }, initOverrides); return await response.value(); } /** * Returns all transactions for a specified category, excluding any pending transactions * Get category transactions */ async getTransactionsByCategoryRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getTransactionsByCategory.'); } if (requestParameters.categoryId === null || requestParameters.categoryId === undefined) { throw new runtime.RequiredError('categoryId', 'Required parameter requestParameters.categoryId was null or undefined when calling getTransactionsByCategory.'); } const queryParameters = {}; if (requestParameters.sinceDate !== undefined) { queryParameters['since_date'] = requestParameters.sinceDate; } if (requestParameters.untilDate !== undefined) { queryParameters['until_date'] = requestParameters.untilDate; } if (requestParameters.type !== undefined) { queryParameters['type'] = requestParameters.type; } if (requestParameters.lastKnowledgeOfServer !== undefined) { queryParameters['last_knowledge_of_server'] = requestParameters.lastKnowledgeOfServer; } const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/categories/{category_id}/transactions`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"category_id"}}`, encodeURIComponent(String(requestParameters.categoryId))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.HybridTransactionsResponseFromJSON)(jsonValue)); } /** * Returns all transactions for a specified category, excluding any pending transactions * Get category transactions */ async getTransactionsByCategory(planId, categoryId, sinceDate, untilDate, type, lastKnowledgeOfServer, initOverrides) { const response = await this.getTransactionsByCategoryRaw({ planId: planId, categoryId: categoryId, sinceDate: sinceDate, untilDate: untilDate, type: type, lastKnowledgeOfServer: lastKnowledgeOfServer }, initOverrides); return await response.value(); } /** * Returns all transactions for a specified month, excluding any pending transactions * Get plan month transactions */ async getTransactionsByMonthRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getTransactionsByMonth.'); } if (requestParameters.month === null || requestParameters.month === undefined) { throw new runtime.RequiredError('month', 'Required parameter requestParameters.month was null or undefined when calling getTransactionsByMonth.'); } const queryParameters = {}; if (requestParameters.sinceDate !== undefined) { queryParameters['since_date'] = requestParameters.sinceDate; } if (requestParameters.untilDate !== undefined) { queryParameters['until_date'] = requestParameters.untilDate; } if (requestParameters.type !== undefined) { queryParameters['type'] = requestParameters.type; } if (requestParameters.lastKnowledgeOfServer !== undefined) { queryParameters['last_knowledge_of_server'] = requestParameters.lastKnowledgeOfServer; } const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/months/{month}/transactions`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"month"}}`, encodeURIComponent(String(requestParameters.month))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.TransactionsResponseFromJSON)(jsonValue)); } /** * Returns all transactions for a specified month, excluding any pending transactions * Get plan month transactions */ async getTransactionsByMonth(planId, month, sinceDate, untilDate, type, lastKnowledgeOfServer, initOverrides) { const response = await this.getTransactionsByMonthRaw({ planId: planId, month: month, sinceDate: sinceDate, untilDate: untilDate, type: type, lastKnowledgeOfServer: lastKnowledgeOfServer }, initOverrides); return await response.value(); } /** * Returns all transactions for a specified payee, excluding any pending transactions * Get payee transactions */ async getTransactionsByPayeeRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getTransactionsByPayee.'); } if (requestParameters.payeeId === null || requestParameters.payeeId === undefined) { throw new runtime.RequiredError('payeeId', 'Required parameter requestParameters.payeeId was null or undefined when calling getTransactionsByPayee.'); } const queryParameters = {}; if (requestParameters.sinceDate !== undefined) { queryParameters['since_date'] = requestParameters.sinceDate; } if (requestParameters.untilDate !== undefined) { queryParameters['until_date'] = requestParameters.untilDate; } if (requestParameters.type !== undefined) { queryParameters['type'] = requestParameters.type; } if (requestParameters.lastKnowledgeOfServer !== undefined) { queryParameters['last_knowledge_of_server'] = requestParameters.lastKnowledgeOfServer; } const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/payees/{payee_id}/transactions`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"payee_id"}}`, encodeURIComponent(String(requestParameters.payeeId))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.HybridTransactionsResponseFromJSON)(jsonValue)); } /** * Returns all transactions for a specified payee, excluding any pending transactions * Get payee transactions */ async getTransactionsByPayee(planId, payeeId, sinceDate, untilDate, type, lastKnowledgeOfServer, initOverrides) { const response = await this.getTransactionsByPayeeRaw({ planId: planId, payeeId: payeeId, sinceDate: sinceDate, untilDate: untilDate, type: type, lastKnowledgeOfServer: lastKnowledgeOfServer }, initOverrides); return await response.value(); } /** * Imports available transactions on all linked accounts for the given plan. Linked accounts allow transactions to be imported directly from a specified financial institution and this endpoint initiates that import. Sending a request to this endpoint is the equivalent of clicking \"Import\" on each account in the web application or tapping the \"New Transactions\" banner in the mobile applications. The response for this endpoint contains the transaction ids that have been imported. * Import transactions */ async importTransactionsRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling importTransactions.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/transactions/import`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))), method: 'POST', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.TransactionsImportResponseFromJSON)(jsonValue)); } /** * Imports available transactions on all linked accounts for the given plan. Linked accounts allow transactions to be imported directly from a specified financial institution and this endpoint initiates that import. Sending a request to this endpoint is the equivalent of clicking \"Import\" on each account in the web application or tapping the \"New Transactions\" banner in the mobile applications. The response for this endpoint contains the transaction ids that have been imported. * Import transactions */ async importTransactions(planId, initOverrides) { const response = await this.importTransactionsRaw({ planId: planId }, initOverrides); return await response.value(); } /** * Updates a single transaction * Update a transaction */ async updateTransactionRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling updateTransaction.'); } if (requestParameters.transactionId === null || requestParameters.transactionId === undefined) { throw new runtime.RequiredError('transactionId', 'Required parameter requestParameters.transactionId was null or undefined when calling updateTransaction.'); } if (requestParameters.data === null || requestParameters.data === undefined) { throw new runtime.RequiredError('data', 'Required parameter requestParameters.data was null or undefined when calling updateTransaction.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/transactions/{transaction_id}`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"transaction_id"}}`, encodeURIComponent(String(requestParameters.transactionId))), method: 'PUT', headers: headerParameters, query: queryParameters, body: (0, index_1.PutTransactionWrapperToJSON)(requestParameters.data), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.TransactionResponseFromJSON)(jsonValue)); } /** * Updates a single transaction * Update a transaction */ async updateTransaction(planId, transactionId, data, initOverrides) { const response = await this.updateTransactionRaw({ planId: planId, transactionId: transactionId, data: data }, initOverrides); return await response.value(); } /** * Updates multiple transactions, by `id` or `import_id`. * Update multiple transactions */ async updateTransactionsRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling updateTransactions.'); } if (requestParameters.data === null || requestParameters.data === undefined) { throw new runtime.RequiredError('data', 'Required parameter requestParameters.data was null or undefined when calling updateTransactions.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/transactions`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))), method: 'PATCH', headers: headerParameters, query: queryParameters, body: (0, index_1.PatchTransactionsWrapperToJSON)(requestParameters.data), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.SaveTransactionsResponseFromJSON)(jsonValue)); } /** * Updates multiple transactions, by `id` or `import_id`. * Update multiple transactions */ async updateTransactions(planId, data, initOverrides) { const response = await this.updateTransactionsRaw({ planId: planId, data: data }, initOverrides); return await response.value(); } } exports.TransactionsApi = TransactionsApi; /** * @export */ exports.GetTransactionsTypeEnum = { Uncategorized: 'uncategorized', Unapproved: 'unapproved' }; /** * @export */ exports.GetTransactionsByAccountTypeEnum = { Uncategorized: 'uncategorized', Unapproved: 'unapproved' }; /** * @export */ exports.GetTransactionsByCategoryTypeEnum = { Uncategorized: 'uncategorized', Unapproved: 'unapproved' }; /** * @export */ exports.GetTransactionsByMonthTypeEnum = { Uncategorized: 'uncategorized', Unapproved: 'unapproved' }; /** * @export */ exports.GetTransactionsByPayeeTypeEnum = { Uncategorized: 'uncategorized', Unapproved: 'unapproved' };