VenditPublicSdk 2024.6.21.1

dotnet add package VenditPublicSdk --version 2024.6.21.1                
NuGet\Install-Package VenditPublicSdk -Version 2024.6.21.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VenditPublicSdk" Version="2024.6.21.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VenditPublicSdk --version 2024.6.21.1                
#r "nuget: VenditPublicSdk, 2024.6.21.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install VenditPublicSdk as a Cake Addin
#addin nuget:?package=VenditPublicSdk&version=2024.6.21.1

// Install VenditPublicSdk as a Cake Tool
#tool nuget:?package=VenditPublicSdk&version=2024.6.21.1                

Vendit logo

Vendit Public API

Building a project using Json files from Swagger documentation has not yet reached the schema maturity of older (Soap) technologies. In order to ease the pain, this c# package should get you up and running faster. Without the need of manually changing generated integers to decimals or Enums...

The API's at https://api2.vendit.online/ can be used by utilizing this client.

This lib is also conveniently available as a NuGet package:

dotnet add package VenditPublicSdk

A minimalistic example, getting today's order ID's (ignoring pagination, so up to 100 orders):

VenditPublicClientSettings settings = new VenditPublicClientSettings
{
    ApiKey   = "XxXxXxXxXxXxXxXxXxXxX",
    Username = "Xx Keep Secret :-) xX",
    Password = "XxXxXxXxXxXxXxXxXxXxX",
};
VenditPublicClient client = new VenditPublicClient(settings);
int[] todaysOrderIds = (await client.FindOrder(OrderFields.OrderDate, DateTime.Today, FilterComparison.GreaterOrEqual)).Results;

More extensive example

Console application that dumps todays orders (max 100) including details to the console output in Json format.

Here we persist the token and the expiry date improving performance (saves a round-trip to get a token on subsequent calls) and slightly increasing security since the credentials are not sent with each use. It is recommended to do something similar in your applications.

Note that you should have separate API Keys for multiple applications or they should have a mechanism for sharing the token. As soon as a new Token is retrieved, the older token will no longer be valid. Having separate API Keys will also help when troubleshooting.

Usage: Run the program once, then fill in your credentials in the ApiSettings.config file, and run again.

using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Security.Authentication;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using VenditPublicSdk;
using VenditPublicSdk.Entities;
using VenditPublicSdk.Entities.Internal;
using VenditPublicSdk.Find;

/// <summary>
/// Writes today's orders with details to standard output (as Json)
/// </summary>
public static class Program
{
    public static async Task Main()
    {
        VenditPublicClientSettings settings = await LoadSettings(CancellationToken.None);
        VenditPublicClient client = new VenditPublicClient(settings) { PersistSettings = PersistSettings };

        // Get all today's orders
        OrderResults orderIds;
        try
        {
            orderIds = await client.FindOrder(OrderFields.OrderDate, DateTime.Today, FilterComparison.GreaterOrEqual);
        }
        catch (AuthenticationException ex)
        {
            Console.WriteLine("Please update ApiSettings.config with your credentials.\r\n" + ex.Message);
            return;
        }

        // Get all Order Details for each order (asynchronously)
        ConfiguredTaskAwaitable<Order>[] orderTasks = new ConfiguredTaskAwaitable<Order>[orderIds.Results.Length];
        for (int t = 0; t < orderTasks.Length; t++)
            orderTasks[t] = client.GetOrderWithDetails(orderIds.Results[t]).ConfigureAwait(false);

        Order[] orders = new Order[orderIds.Results.Length];

        for (int t = 0; t < orderTasks.Length; t++)
            orders[t] = await orderTasks[t];

        // Do something with the orders
        string ordersAsJson = JsonConvert.SerializeObject(orders, Formatting.Indented);
        Console.WriteLine(ordersAsJson);
    }

    /// <summary>
    /// This will automatically be called when a Token in outdated..
    /// Store the token and its expiration date somewhere safe (e.g. in a database)
    /// In this example we simply store all settings in a config file
    /// </summary>
    private static async Task PersistSettings(VenditPublicClientSettings settings, CancellationToken cancel)
    {
        await using (FileStream settingsFile = File.Create("ApiSettings.config"))
        await using (StreamWriter writer = new StreamWriter(settingsFile, Encoding.UTF8))
            await writer.WriteAsync(JsonConvert.SerializeObject(settings, new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented, 
                DefaultValueHandling = DefaultValueHandling.Ignore,
                NullValueHandling = NullValueHandling.Ignore
            }));
    }

    /// <summary>
    /// Checks if a config file exists, if not creates one...
    /// Your code should store credentials safely and make sure the Token and expiration date are also retrieved for better
    /// performance (saves a GetToken round trip) and less frequent logins (exposure of credentials).
    /// </summary>
    private static async Task<VenditPublicClientSettings> LoadSettings(CancellationToken cancel)
    {
        if (!File.Exists("ApiSettings.config"))
        {
            VenditPublicClientSettings empty = new VenditPublicClientSettings
            {
                // Don't bother editing these here, run the program once and then update ApiSettings.config with your credentials

                ApiKey   = "XxXxXxXxXxXxXxXxXxXxX",
                Username = "Xx Keep Secret :-) xX",
                Password = "XxXxXxXxXxXxXxXxXxXxX",
            };
            await PersistSettings(empty, cancel);
            return empty;
        }

        await using (FileStream settingsFile = File.OpenRead("ApiSettings.config"))
        using (StreamReader sr = new StreamReader(settingsFile, Encoding.UTF8))
            return JsonConvert.DeserializeObject<VenditPublicClientSettings>(await sr.ReadToEndAsync(cancel));
    }
}

documentation

More info can be found in the Docs.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.6.21.1 121 6/21/2024
2024.5.7.2 111 5/7/2024
2024.5.7.1 110 5/7/2024

Initial public release