softwerkab / fortnox-csharp-api-sdk

.NET SDK for Fortnox API.
MIT License
52 stars 64 forks source link

VoucherRows missing in Vouchers #153

Closed TeemuLattiLuja closed 3 years ago

TeemuLattiLuja commented 3 years ago

Hello

Is it possible to get voucherRows from Vouchers? I tried this with Postman and when I get all records from Vouchers it doesn't show voucherRows in response. But when I get a single voucher it shows VoucherRows in response.

So I would like to see voucherRows in response when I get all the records of vouchers.

Best regards Teemu

richardrandak commented 3 years ago

Hello! Unfortunetely not, the Fortnox API is designed this way. You can either get the single voucher with all the details, or a list of vouchers with limited subset of properties. If you need all the rows for all the vouchers, using voucher endpoint may not be suitable due to the request rate limit. What are you trying to achieve? Maybe getting a SIE file with all transactions may be better approach

TeemuLattiLuja commented 3 years ago

Thanks for the quick response!

I think I need to rethink what would be the most suitable way in my case. Maybe I can deal with getting single voucher with all the details.

TeemuLattiLuja commented 3 years ago

Do you know if it is possible to convert SIE file to JSON,CSV or XML?

I need to get all voucherRows into my sql server database and you were right that voucher endpoint isn't suitable because the request rate limit. With SIE file I can get all the voucherRows with one request but this file format is something new to me.

richardrandak commented 3 years ago

I don't know about that.. but here is the SIE specification - https://sie.se/wp-content/uploads/2020/05/SIE_filformat_ver_4B_ENGLISH.pdf ..SIE is a standard format for accounting systems in Sweden

Basically a row with #VER tag is a voucher containing several rows with #TRANS tag representing a transaction (voucher row). You should be able to extract what you need from there

Here is a simple parser as NuGet - https://www.nuget.org/packages/jsisie which I am using for my integrations.

richardrandak commented 3 years ago

Here is some sample I made for you.

var sieConnector = fortnoxClient.Get<SIEConnector>();
            var data = sieConnector.Get(SIEType.Transactions, finYearId);

            //SIE from Fortnox is encoded in PC-8 (Code page 437) 
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var sieDocument = new SieDocument();
            sieDocument.ReadDocument(new MemoryStream(data));

            foreach (var sieVoucher in sieDocument.VER)
            {
                var series = sieVoucher.Series;
                var date = sieVoucher.VoucherDate;
                //...//

                foreach (var sieVoucherRow in sieVoucher.Rows)
                {
                    var amount = sieVoucherRow.Amount;
                    var account = sieVoucherRow.Account.Number;
                    var text = sieVoucherRow.Text;
                    // ... //
                }
            }
TeemuLattiLuja commented 3 years ago

This looks promising! I copied your example and tried it but it gives me jsiSIE.SieVoucherMissmatchException 'A.68 Sum is not zero'. It comes from row "sieDocument.ReadDocument(new MemoryStream(data));".

richardrandak commented 3 years ago

Hmm.. I am not the author of the parser, and haven't seen this exception before.. but.. from the exception message, I would assume the voucher A68 is not be balanced.. which would be weird, I thought that can not happen in Fortnox :) You should check the voucher

TeemuLattiLuja commented 3 years ago

So I talked with finance department and took a closer look to the SIE file. There were some vouchers that were manually fixed to balance in Fortnox and those were the problem. Got it working now.

Thanks for your help!