Api to import ofx?

My bank allow to download daily transaction statements which I convert to ofx.


Now, is there a way to either via api tout import the ofx file like I the UI or at least be able to select multiple files when importing?

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Cyan Transistor - The API doesn't natively support uploading an OFX file but you could write something that parses the OFX file and hits the /budgets/{budget_id}/transactions endpoint to create/import the transactions.  Also, the web File-Based Import only supports one file at a time.  Hope this helps!

  • Any chance of adding multiple files support for import or have more explicit api for import ? Especially since it seems api imported statements don't seem to be possible to setup to cleared nor automatically grouped.

    • Cyan Transistor You could submit a Feature Request for the ability to upload multiple OFX files through File-based Import on the web application.

      As for importing the OFX files through the API, I threw together an example (below) using Node.js (JavaScript), using the ofx package to parse OFX files and import multiple files through the API.  This is crude and not fully tested but I was able to import an OFX using it and will hopefully be enough to get you going in the right direction.

      var fs = require("fs");
      var ofx = require("ofx");
      var ynab = require("ynab");
      const accessToken = "123-not-real-456";
      const targetYNABAccountId = "789-not-real-012";
      const sourceOfxFiles = ["bank-export-1.ofx", "bank-export-2.ofx"];
      function addTransactionsFromOfxFile(filePath, transactions) {
        const ofxRawData = fs.readFileSync(filePath, "utf8");
        const ofxParsed = ofx.parse(ofxRawData);
        for (let txn of ofxTransactions) {
          const id = txn.FITID;
          const dateISO = `${txn.DTPOSTED.substr(0, 4)}-${txn.DTPOSTED.substr(4,2)}-${txn.DTPOSTED.substr(2, 2)}`;
          const amountMilliunits = txn.TRNAMT * 1000;
          const memo = txn.MEMO;
            import:id: id,
            account_id: targetYNABAccountId,
            cleared: ynab.SaveTransaction.ClearedEnum.Cleared,
            approved: true,
            date: dateISO,
            amount: amountMilliunits,
            payee_name: memo
      async function importTransactionsToYNAB(accessToken, transactions) {
        const ynabAPI = new ynab.API(accessToken);
        await ynabAPI.transactions.createTransactions("last-used", { transactions });
      (async () => {
        const transactions = [];
        for (let ofxFile of sourceOfxFiles) {
          addTransactionsFromOfxFile(ofxFile, transactions);
        await importTransactionsToYNAB(accessToken, transactions);
      Like 1
  • Thanks! would these imported transactions get the payee rules applied ? and can they be cleared like file imported transaktions? 

    • Cyan Transistor If an import_id is specified and a payee_name is specified, then yes, the payee rules will get applied.  See the "Model" area of the endpoint documentation for more details.  

      I've updated the example above to specify an import_id (using the FITID field from the OFX file) and also passing in the memo as the payee_name.  There a lots of variations for how data is represented on OFX files so you'll want to check your bank's file and make adjustments as necessary.

      Also, yes, they can be marked as cleared.  In the example above, I'm specifying

      cleared: ynab.SaveTransaction.ClearedEnum.Cleared

      will will mark them as cleared when imported.

Like Follow
  • 1 yr agoLast active
  • 5Replies
  • 196Views
  • 2 Following