Giter VIP home page Giter VIP logo

csharp-api-sdk's Introduction

GitHub release nuget License: MIT

Fortnox .NET SDK

.NET SDK package for developing integrations towards Fortnox REST API. The package is developed and maintained by Softwerk AB.

For more information about the API, please visit the official documentation at https://developer.fortnox.se/.

Get started

Get help

  • For help regarding this package and more code examples visit our wiki.
  • For help regarding the main API please visit https://developer.fortnox.se/
  • For help regarding release information visit our changelog.
  • For other help about our package please file an issue.

csharp-api-sdk's People

Contributors

adamelfstrom avatar aztherion avatar davidulvmoen avatar dpse avatar itstodsiik avatar jakobhaggcab avatar jesper72 avatar krydd avatar lukaslonnroth avatar masrooj avatar mgefvert avatar richardrandak avatar saarsoo avatar sharparam avatar tommykfortnox avatar tonimontana avatar tsfcode avatar vanillajonathan avatar williamganrotyoucal avatar wmartin129 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharp-api-sdk's Issues

Customer.Type=UNDEFINED orsakar problem

Vi skickar kunder till Fortnox F3 API. Vid uppdatering vill vi inte att Type i Fortnox ändras, dvs vi vill skippa Type. Hur får man till det via SDK?

Har provat att sätta till UNDEFINED, men det ger fel i Fortnox.

Querying Customers

What is the reason behind that I can't find the Customer record with the organisationNumber 123456789 when I query with 123456789 but I can find with 12345678 on sandbox api?

Also if the organisationNumber is 12345678 I can find it with querying as 12345678.

Properties and types

I noticed that all properties are created as strings. For some fields this is not a problem, but for example when creating an order and setting the Price property, the API responds with an error that the type must be a float. I changed this manually in https://github.com/FortnoxAB/csharp-api-sdk/blob/master/FortnoxAPILibrary/Entities/Order.cs and it works fine, but shouldnt all properties be typed according to eg https://developer.fortnox.se/documentation/resources/orders/ ?

Problem med VoucherSubSets

Jag har problem med att hämta VoucherSubSets, har testat både koden nedan, med loop och loop med sleep. Har öven testat med Offset istället för att ändra page, fick samma problem där. Problemet är att när en tredje voucherCon.Find() körs returnerar den null med ErrorCode och ErrorMessage som kan ses nedan.

voucherCon.Limit = 2;
var voucherResult = voucherCon.Find();
voucherCon.Page = 2;
var voucherResult2 = voucherCon.Find();
voucherCon.Page = 3;
var voucherResult3 = voucherCon.Find();

ErrorCode: 2000762
ErrorMessage: No such route

SupplierInvoice

I want to create supplier invoices. Where can set more information such as Orgnr, supplier's account nr/BG/PG, objectnr, ordernr?

SupplierInvoiceConnector sic = new SupplierInvoiceConnector();
SupplierInvoice si = new SupplierInvoice();
si.InvoiceNumber = "101";
si.OCR = "1010120101";
si.InvoiceDate = "2017-05-25";
si.DueDate = "2017-06-25";

sic.Create(si);

Remove call to appdomain-wide setting of allowed TLS protocols

061a8c5

This makes the whole application vulnerable where the library is used as it will change the allowed security protocols not only for this library but for the whole application.

If a user of the library needs to change the settings of ServicePointManager it can do so in their app. Libraries should not change this global object.

This is known best practices and this should be treated as a security vulnerability in the library.

Best practices:
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls

We recommend that you:

  • Do not specify the TLS version. Configure your code to let the OS decide on the TLS version.
  • Perform a thorough code audit to verify you're not specifying a TLS or SSL version.

It's also really bad that this wasn't mentioned in the release notes here:
https://github.com/FortnoxAB/csharp-api-sdk/releases/tag/3.1.0

I would want to ask you to reveret the commit above and withdraw the 3.1.0 release before releasing this to nuget (where it will get a much larger spread than here on Github).

dotnetcore standard 2.0 compatible

Do you have any plans in making this compile using dotnetcore standard 2.0?

Warning NU1701: Package 'Fortnox.NET.SDK 3.0.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

The calls I have made so far does work.

ConnectionCredentials race condition

If this sdk is used in a multi user environment, like an ASP.NET IIS web application, we will have a race condition since the static properties in ConnectionCredentials is shared in the application domain.

So all user requests that triggers Fortnox communication, will replace the AccessToken property with their own token, so it is possible that user A ends up using user B's token.

Hämta filtrerad kundlista

Kan man på något sätt begränsa vilka kunder man hämtar med Find() utöver det självklara att ange en property i connectorn? Jag vill kunna hämta alla kunder med TYPE==COMPANY och exkludera TYPE==PRIVATE men det går inte i connectorn

Connector to Salary Transactions

I also miss the Connector to Salary Transactions. (As well as Nox Finans). The solution for now is to import the whole API into my project, and make new classes as they are missing. But it seems a bit odd they are not in the Official API.

Update Invoice created from Order

When updating an Invoice that has been created from an Order (setting NotCompleted to True) you get an error message saying "En eller flera rader har koppling till en order, det går därför inte att uppdatera raderna via API."
This can be done with a REST call but not with the SDK.

Full entity from connectors

Hi,

This is the first time I'm trying to do a project in .net and C#, so please be patience with my question.

Can someone help me to get full entity from connectors?

Entities

Connector to NoxFinans

Hi! There is no Connector to Nox Finans in this API. Are you planning to make such a connector? If not, do you have a suggestion as to how to solve the problem? The only way I see now is to import the whole API and make our own version? It does not seem to be possible to make a new Class that extends EntityConnector, or FinancialYearBasedEntityConnector, as there are internal fields/classes involved, unless one makes a new version of the whole solution.

How to get supplier invoice preview pdf

We want import fortnox customer invoice and supplier invoice into our website, we use C# API to get the invoices. we want view the invoice preview PDF. As the InvoiceSubset(return by invoiceConnector) don't provide pdf url, so we use invoiceConnector.Preview() to save the PDF at local. But when we import the supplier invoice PDF as customer invoice, it doesn't work. We use SupplierInvoiceFileConnectionConnector get supplier invoice file, then loop the files and save the file at local, but SupplierInvoiceFileConnectionConnector return nothing. Could you please help us get the supplier invoice preview PDF?
image

Using double as data type for money?

Hi @richardrandak!

Thank you for maintaining the sdk.

I noticed you commit 4dc42ab Fix types for entity properties, where you change a lot of properties from string to typed data.

Is there any thought behind choosing double for all properties representing money? Usually a good practice is to use decimal as data type when a variable represents financial and monetary values because floats and doubles cannot accurately represent the base 10 multiples that we use for money.

Read more.

Default language

There doesnt seem to be a field for setting the default language on orders, invoices etc on a customer.
I could not find a parameter for this in either the rest api or the SDK.
It is possible to set the language on invoices created through the rest api or SDK, but of course this doesnt affect the customer defaults.

image

Target NETStandard

Since this project has no external dependencies it would be quite easy to convert to target netstandard2.0 and net47 in a mixed configuration. The only thing missing in netstandard2.0 is the mimetype parser which needs a dependency, or code for the parser
https://github.com/vforteli/csharp-api-sdk

DefaultDeliveryTypes is overridden when updating Customer

When following the instructions here for updating a Customer, the Customers DefaultDeliveryTypes are all set to EMAIL.

This seems to be the issue, with DefaultDeliveryTypes being set in the constructor for the Customer class.

This clashes with the statement that only the properties that you provide will be updated.

The request was aborted: Could not create SSL/TLS secure channel

I am in the early stages of integrating Fortnox with our project and ran into this issue on the first example I tried.

ArticleConnector articleConnector = new ArticleConnector();
articleConnector.AccessToken = "********-****-****-****-***********";
articleConnector.ClientSecret = "*********";
Articles result = articleConnector.Find();

This would throw the exception: "The request was aborted: Could not create SSL/TLS secure channel"
I ran wireshark and noted that the handshake was attempted with TLSv1 whereas api.fortnox.se runs TLSv1.3. I managed to remedy this by simply retargeting the project to .NET 4.8 and adding the following line to UrlRequestBase.SetupRequest

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;

Making it:

internal HttpWebRequest SetupRequest(string requestUriString, string method)
{
	Error = null;

	HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create(requestUriString);
	wr.Headers.Add("access-token", this.AccessToken);
	wr.Headers.Add("client-secret", this.ClientSecret);
	wr.ContentType = "application/xml";
	wr.Accept = "application/xml";
	wr.Method = method;
	wr.Timeout = this.Timeout;
	ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
	return wr;
}

I'm sure there's a better place for this, but it worked in my case.

OpenAPI/Swagger api reference document

It would be very useful to have an API description/reference in OpenAPI format for e.g. testing the developer account in PostMan (or something equal)

Using this OpenAPI/Swagger file, you/developers should also be able to generate client libraries for your API. Not all users of Fortnox will be using csharp.

"Kan inte logga in, access-token eller client-secret saknas."

Jag har fyllt i min Access-Token/at och min Client-Secret/cs där det är meningen.
Inuti UrlRequestBase.cs har jag lagt till i error medelandet att den ska skriva vad den uppfattar som min at och cs;
throw new Exception("Kunde inte tolka felmeddelandet från Fortnox API.\n\n" + text +"\n\n AT: "+accessToken+"/"+AccessToken +"\n\n CS: "+clientSecret+"/"+ClientSecret+"\n\n", ex.InnerException);
Så när jag kompilerar programmet så står det i error medelandet, att min at och cs är helt korrekt, så förstår inte varför api;n ger mig ett error

{"ErrorInformation":{"Error":1,"Message":"Kan inte logga in, access-token eller client-secret saknas.","Code":2000311}}

Search articles?

For example: Search att articles where StockWarning > DisposableQuantity.

Cannot se any way to do this.

And when I get a list of all articles, the Property 'StockWarning' is missing...

The search for Reference Number is broken

Search for ReferenceNumber using the following example code

TaxReductionConnector taxreductionConnector = new TaxReductionConnector();
taxreductionConnector.ReferenceNumber = "123";

Expected:
The taxreductionConnector with ReferenceNumber 123 should be returned

Actual:
No results are returned

External reference: NETSDK-68

Write to messages?

Hi!
I cannot find anything in documentation of API or SDK about writing messages to users. Is this possible? If not, can it be made possible?

Scenario: We export some invoice to some other place, and on the way it's validated for some properties that are required by receiver, but not by Fortnox. When this happens we want to notify the user that the property needs to be fixed for us to be able to export it, "Hey, we could not export invoice number {x} to {receiver} becuase {property} is [missing|invalid]. Please correct this.". We could send an email, but it would be more user friendly to send the notification as a message in Fortnox.

image

Order Rows

The Order Connector seems to give access to the order headers. Is there a way to read the order rows? Is the functionality missing in the SDK?

please help!

The following code stops looping after 15 pages (iLoop = 16). Can someone please help me to understand why.

Get this error message:

verifikat_null

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FortnoxAPILibrary.Connectors;
using FortnoxAPILibrary;
using System.Web;
using System.Threading;
using static System.Net.Mime.MediaTypeNames;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{

            Excel.Application oXL;
            Excel._Workbook oWB;
            Excel._Worksheet oSheet;
            Excel.Range oRng;

            //Start Excel and get Application object.
            oXL = new Excel.Application();
            oXL.Visible = true;

            //Get a new workbook.
            oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
            oSheet = (Excel._Worksheet)oWB.ActiveSheet;

            //Add table headers going cell by cell.
            oSheet.Cells[1, 1] = "Verifikat";
            oSheet.Cells[1, 2] = "Datum";
            oSheet.Cells[1, 3] = "Beskrivning";
            oSheet.Cells[1, 4] = "Konto";
            oSheet.Cells[1, 5] = "Debit";
            oSheet.Cells[1, 6] = "Kredit";

            //Format A1:D1 as bold, vertical alignment = center.
            oSheet.get_Range("A1", "F1").Font.Bold = true;
            oSheet.get_Range("A1", "F1").VerticalAlignment =
            Excel.XlVAlign.xlVAlignCenter;

            var VouchersConnector = new VoucherConnector();

            VouchersConnector.ClientSecret = "abc123";
            VouchersConnector.AccessToken = "abc123";

            for (int iloop = 1; iloop < 61; ++iloop)
            {

            VouchersConnector.Limit = 500;

            VouchersConnector.Page = iloop;

            VouchersConnector.FinancialYearID = "1";
            var verifikat = VouchersConnector.Find();

            int rownumber = 2;

            foreach (var item in verifikat.VoucherSubset)
            {
                var voucherNumber = item.VoucherNumber;
                var voucherSeries = item.VoucherSeries;
                var test = VouchersConnector.Get("A", voucherNumber);
                var vatCode = test.VoucherSeries;
                var desc = test.Description;
                var rows = test.VoucherRows;
                var vdate = test.TransactionDate;

                foreach(var VoucherRow in rows)
                {

                    var deb = VoucherRow.Debit;
                    var cred = VoucherRow.Credit;
                    var acc = VoucherRow.Account;
                    var varRowsCount = rows.Count;

                    oSheet.Cells[rownumber, 1] = voucherSeries + voucherNumber;
                    oSheet.Cells[rownumber, 2] = vdate;
                    oSheet.Cells[rownumber, 3] = desc;
                    oSheet.Cells[rownumber, 4] = acc;
                    oSheet.Cells[rownumber, 5] = deb;
                    oSheet.Cells[rownumber, 6] = cred;

                    rownumber = rownumber + 1;

                }

                Thread.Sleep(250);

            }
        }


    }

}

}

Skapande av tomma rader i en faktura orsakar problem

Nu skapas alla fakturor manuellt. De tre första raderna används för "header" information. Det går utmärkt och allt blir som det ska. Se bild 1.

I den applikation som jag utvecklar ska fakturor skapas automatiskt och se likadana ut som de manuellt skapade. Mitt problem är att jag inte kan skapa tomma rader. Det som verkar vara problemet är att DiscountType sätts automatiskt till AMOUNT, se bild 2.

DiscountType skickas också till Fortnox som enda parameter vid skapandet av en rad.

<InvoiceRow>
  <DiscountType>AMOUNT</DiscountType>
</InvoiceRow>

Det jag tror händer är att Konto, Moms och Ks sätts automatiskt till defaultvärden pga att DiscountType sätts till ett värde. Se bild 3.

Problemet uppstår när man bokför fakturan. Då skapas det en post på konto 3001 som är 0kr, se bild 4.

Min fråga är om någon vet hur jag kan fixa detta genom att fortfarande använda FortnoxAPILibrary, eller om det är omöjligt och jag måste använda en annan metod.


manuellt skapad faktura
Bild 1: Manuellt skapad faktura.


discounttype problem
Bild 2: Skapandet av tom rad.


fakturaunderlag med felaktig information
Bild 3: Fakturaunderlag med felaktig information


huvudbok 3001
Bild 4: Huvudbok, konto 3001

Alla primitives är av typen sträng

Hej,

Är det någon speciell anledning att alla primitves på era entiteter är av typen sträng?

T ex: StockQuantityArticle: https://github.com/FortnoxAB/csharp-api-sdk/blob/master/FortnoxAPILibrary/Entities/Article.cs#L427

Här anser jag det mest logiska borde vara att låta StockQuantity vara av typen int?

Som utvecklare mot ert API hade det underlättat enormt att inte behöva casta om alla nummer och booleans till strängar - med avseende både tidsmässigt och felkänsligheten det medför.

/Martin

Problem with articlenumbers containing "/" giving "No such route"

The purpose of this issue is to add info to the shared knowledge-base in this forum.

We recently had a problem to GET info about an article with article number "FG-B/S". The problem was that HttpWebRequest.Create() unescapes strings such as "%2F" for security reasons.

However that behavior can be turned off (.NET 4.5+) using this piece of XML in web.config:

<configuration>
  <uri>
    <schemeSettings>
      <add name ="https" genericUriParserOptions="DontUnescapePathDotsAndSlashes" />
    </schemeSettings>
  </uri>
</configuration>

Pagination

How do I get the AccountSubset to go to the next page in a loop?

This code does not works properly:

        for (int iloop = 0; iloop < ipage; ++iloop)
        {
      
            page = page + 1;
            string stringpage = page.ToString();

            konton.CurrentPage = stringpage;
        
            Console.WriteLine(stringpage);

            foreach (var item in konton.AccountSubset)
            {
             
                konton.CurrentPage = stringpage;
                var accountNumber = item.Number;
                var test = AccountConnector.Get(accountNumber);
                var vatCode = test.VATCode;
                var sru = item.SRU;
            
                Console.WriteLine(accountNumber + " - " + vatCode + " - " + sru);

                Thread.Sleep(250);

            }
        }

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.