From 517219e6aad1d4e6f4ed2f9996d6e9a75128ff8b Mon Sep 17 00:00:00 2001 From: David Ulvmoen <31989721+davidulvmoen@users.noreply.github.com> Date: Wed, 11 Oct 2017 10:35:04 +0200 Subject: [PATCH] Update README.md --- README.md | 295 ++++++------------------------------------------------ 1 file changed, 28 insertions(+), 267 deletions(-) diff --git a/README.md b/README.md index 2917658a..c36920f9 100644 --- a/README.md +++ b/README.md @@ -1,288 +1,49 @@ -[![NuGet](https://img.shields.io/nuget/v/PayPal.svg)](https://www.nuget.org/packages/Fortnox.NET.SDK) +[![GitHub release](https://img.shields.io/github/release/FortnoxAB/csharp-api-sdk.svg)]() [![nuget](https://img.shields.io/nuget/v/Fortnox.NET.SDK.svg)](https://www.nuget.org/packages/Fortnox.NET.SDK/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -# csharp-api-sdk -Official .NET SDK for developing integrations towards the Fortnox API. This is a guide to help developers to get started with the .NET SDK by developing a simple console application which creates, retrives, deletes and search for a customer. For a full API reference please visit [developer.fortnox.se/documentation/](http://developer.fortnox.se/documentation/) +*** + -## Install package via nuget +## Fortnox .NET SDK +Official .NET SDK package for developing integrations towards Fortnox REST API. Please note that this package is not totally aligned with the main API, however we are pretty close and will strive to keep up the pace. For more information please visit the official documentation https://developer.fortnox.se/. -## Connect to Fortnox API -Before we can send and receive any data to/from Fortnox we need to provide an `access-token` and a -`client-secret`. This is done by using the static class `ConnectionCredentials` and the properties -`AccessToken` and `ClientSecret`. -```C# -static void Main(string[] args) -{ - ConnectionCredentials.AccessToken = "{Generated GUID}"; - ConnectionCredentials.ClientSecret = "{Generated alphanumeric string}"; -} -``` - -## Error handling -To capture all error messages it is recommended to always use try - catch statements. - -```C# -static void Main(string[] args) -{ - ConnectionCredentials.AccessToken = "{Generated GUID}"; - ConnectionCredentials.ClientSecret = "{Generated alphanumeric string}"; - - try - { - - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } -} -``` - -## Create a customer -To create a customer we start by creating an instance of the Customer object. With an instance in place we populate it with data. - -> NOTE! All fields in the SDK are of type string. - -```C# -static void Main(string[] args) -{ - ConnectionCredentials.AccessToken = "{Generated GUID}"; - ConnectionCredentials.ClientSecret = "{Generated alphanumeric string}"; - - try - { - Customer customer = new Customer(); - customer.CustomerNumber = "1"; - customer.Name = "Stefan Andersson"; - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } -} -``` - -To be able to create, update, delete a customer in Fortnox we have to create an instance of -`CustomerConnector` which is the class that handles the communication with Fortnox. - - -```C# -static void Main(string[] args) -{ - ConnectionCredentials.AccessToken = "{Generated GUID}"; - ConnectionCredentials.ClientSecret = "{Generated alphanumeric string}"; - - try - { - Customer customer = new Customer(); - customer.CustomerNumber = "1"; - customer.Name = "Stefan Andersson"; - - CustomerConnector customerConnector = new CustomerConnector(); - customerConnector.Create(customer); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } -} -``` - -### Error handling -To check if there was a problem when creating the customer we check if the property `HasError` on the -`CustomerConnector` object is true. - -```C# -if (customerConnector.HasError) -{ - Console.WriteLine(customerConnector.Error.Message); -} -``` - -### Creating a customer - complete example +## Get started +* Register as a Fortnox Developer +* Install nuget package Fortnox.NET.SDK +* Start coding -```C# -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FortnoxAPILibrary; -using FortnoxAPILibrary.Connectors; - -namespace FortnoxAPILibraryDemo -{ - class Program - { - static void Main(string[] args) - { - ConnectionCredentials.AccessToken = "{Generated GUID}"; - ConnectionCredentials.ClientSecret = "{Generated alphanumeric string}"; - - try - { - Customer customer = new Customer(); - customer.CustomerNumber = "123"; customer.Name = "Customer 123"; - - CustomerConnector customerConnector = new CustomerConnector(); - - Customer createdCustomer = customerConnector.Create(customer); - - if (customerConnector.HasError) - { - Console.WriteLine(customerConnector.Error.Message); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - } -} +```CSharp + var customerConnector = new CustomerConnector(); + var customer = new Customer(); + customer.CustomerNumber = "1"; + customer.Name = "Stefan Andersson"; + customerConnector.Create(customer); ``` -## Get a specific customer -To get a specific customer from Fortnox we use the method `Get` on the `CustomerConnector` object. -The `Get` method takes a customer number as parameter and returns the customer that was found. If -no customer is found we get an error message in the property `CustomerConnector.Error.Message`. - -### Getting a customer with CustomerNumber 123 - complete example - -```C# -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FortnoxAPILibrary; -using FortnoxAPILibrary.Connectors; - -namespace FortnoxAPILibraryDemo -{ - class Program - { - static void Main(string[] args) - { - ConnectionCredentials.AccessToken = "{Generated GUID}"; - ConnectionCredentials.ClientSecret = "{Generated alphanumeric string}"; - - try - { - CustomerConnector customerConnector = new CustomerConnector(); - Customer customer = customerConnector.Get("123"); - - if (customerConnector.HasError) - { - Console.WriteLine(customerConnector.Error.Message); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - } -} +```VB + Dim customerConnector As New CustomerConnector() + Dim customer As New Customer() + customer.CustomerNumber = "1"; + customer.Name = "Stefan Andersson"; + customerConnector.Create(customer); ``` -## Searching for customers -If you want to search for customers you use the method `Find` on the `CustomerConnector` object. The -method `Find` takes no parameters and returns a list of customers. - -To be able to limit the search results you use the properties of the `CustomerConnector` object. See -the code example below where the customer name is the parameter to search for. It is possible to -combine as many search parameters as you want. - -Please refer to the [API documentation](http://developer.fortnox.se/documentation/resources/customers/) for more information on which fields that are searchable. -### Search for a customer named Stefan - Complete example +## 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 a issue. -```C# -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FortnoxAPILibrary; -using FortnoxAPILibrary.Connectors; -namespace FortnoxAPILibraryDemo -{ - class Program - { - static void Main(string[] args) - { - ConnectionCredentials.AccessToken = "{Generated GUID}"; - ConnectionCredentials.ClientSecret = "{Generated alphanumeric string}"; - - try - { - CustomerConnector customerConnector = new CustomerConnector(); - customerConnector.Name = "Stefan"; - Customers customers = customerConnector.Find(); - - if (customerConnector.HasError) - { - Console.WriteLine(customerConnector.Error.Message); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - } -} -``` - -> NOTE! There is a difference between the objects `Customer` and `Customers`. `Customer` is used when a single customer is returned and `Customers` is returned when a list of customers is returned. - -## Deleting a customer -To delete a customer the method `Delete` on the `CustomerConnector` object is used. The method takes -a customer number as parameter and returns nothing. - -### Deleting a customer - complete example -```C# -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FortnoxAPILibrary; -using FortnoxAPILibrary.Connectors; - -namespace FortnoxAPILibraryDemo -{ - class Program - { - static void Main(string[] args) - { - ConnectionCredentials.AccessToken = "{Generated GUID}"; - ConnectionCredentials.ClientSecret = "{Generated alphanumeric string}"; - - try - { - CustomerConnector customerConnector = new CustomerConnector(); - customerConnector.Delete("123"); - - if (customerConnector.HasError) - { - Console.WriteLine(customerConnector.Error.Message); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - } -} -``` -# Licence +# Get licence The MIT License (MIT) -Copyright (c) 2015 Fortnox AB, Jesper Svensson +Copyright (c) 2017 Fortnox AB, Jesper Svensson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal