LockstepSdk 2023.13.37

.NET Standard 2.0
dotnet add package LockstepSdk --version 2023.13.37
NuGet\Install-Package LockstepSdk -Version 2023.13.37
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="LockstepSdk" Version="2023.13.37" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LockstepSdk --version 2023.13.37
#r "nuget: LockstepSdk, 2023.13.37"
#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 LockstepSdk as a Cake Addin
#addin nuget:?package=LockstepSdk&version=2023.13.37

// Install LockstepSdk as a Cake Tool
#tool nuget:?package=LockstepSdk&version=2023.13.37

Lockstep SDK for C#

Nuget

Repository Description

This software development kit allows you to connect with the Lockstep Platform SDK using C#. This README describes the steps (mentioned in the "Fetch Invoices" tutorial) to write a C# program that uses this SDK to fetch invoices.

Many types of products examine invoices for a customer and provide feedback on them. A typical product might analyze incoming invoices and add metadata like a credit score for each invoice. This tutorial explains how to iterate through invoices, examine them, and add metadata.

We use the Query Invoices API to retrieve a collection of invoices. To fetch a large number of invoices, we must use filtering and pagination.

How to Write a Program Using This SDK

Step 1: Install Lockstep SDK for C#

Before you start, make sure you generated a valid API key and saved it as an environment variable in your system (referred to as LOCKSTEPAPI_SBX in this example). That way, you'll have access to the server.

Create a new project folder with an empty Program.cs file inside it and add the SDK to your project:

  • One way to add the SDK to your project is by using the package manager:

    dotnet add package LockstepSdk
    
  • Another way is to locate the source code in the /src/ folder of this repository and ensure that your project folder has access to it (download and add it using your IDE).

There may be some additional dependencies you have to install.

Step 2: Declare and initialize Lockstep API

Open your Program.cs file. Start by listing the dependencies and creating the main method. This main method should have variables for the client and apiKey. Note that the string passed in Environment.GetEnvironmentVariable() matches the environment variable name you created on your system. The Ping() method verifies your program can access the Lockstep Platfom API, regardless of authentication status or permissions.

using System;
using LockstepSDK;

namespace LockstepExamples
{
    public class CSharpExample
    {
        public static async Task Main(string[] args)
        { 
            var client = LockstepApi.WithEnvironment(LockstepEnv.SBX)
                .WithApiKey(Environment.GetEnvironmentVariable("LOCKSTEPAPI_SBX"));

            // Test first API call
            var result = await client.Status.Ping();
            if (!result.Success || !result.Value.LoggedIn)
            {
                Console.WriteLine("Your API key is not valid.");
                Console.WriteLine("Please set the environment variable LOCKSTEPAPI_SBX and try again.");
                return;
            }

            // Print some information about our current user
            Console.WriteLine($"Ping result: {result.Value.UserName} ({result.Value.UserStatus})");
            Console.WriteLine($"Server status: {result.Value.Environment} {result.Value.Version}");
            Console.WriteLine();
            
            // You may now use the client object to make API calls
        }
    }
}

Step 3: Create API query

In the while loop, we can begin querying invoices by storing the results in the invoices variable. Using the QueryInvoices API, we will fetch all invoices dated from December 1st, 2021 and later. We specify a page size of 100, which gives us a small number of invoices in each query.

var invoices = await client.Invoices.QueryInvoices(
    "invoiceDate > 2021-12-01",     // filter
    "Customer",                     // include
    "invoiceDate asc",              // order
    100,                            // pageSize
    0                               // pageNumber
);

The results from this API call will list the first 100 invoices, since you specified a page size of 100. Your results will include a field called totalCount, which tells you exactly how many records that matched your filter:

{
    "records": [
        {
            "groupKey": "1c043d8f-ce7e-4cf6-aa8e-a08b0220d327",
            "invoiceId": "23c57f74-b643-47bf-a82b-c90984b1fc1b",
            "companyId": "dab105d3-8fa3-4c4d-990a-c00cac91a064",
            "customerId": "453060e9-393e-4584-a5f6-31d8581c3969",
            "erpKey": "58784FB2-DD9F-4CAB-B672-575922DBFE3F",
            "purchaseOrderCode": "07E9A",
            "referenceCode": "DEMOI000000010",
            ...
        }
    ],
    "totalCount": 1919,
    "pageSize": 100
}

The results we get back also includes information about the company that wrote the invoice, since we added "Customer" to the include parameter of the query. Thus, we can fetch invoices and companies within the same query rather than making separate API calls.

Step 4: Iterate through query results

Looking at the previous output, notice that records was returned. We can access each invoice by iterating through invoices.Value.Records. We can print details about each invoice by accessing its fields, such as InvoiceId and OutstandingBalanceAmount. And since we added "Customer" to the include parameter, we can access that to print the CompanyName:

foreach (var invoice in invoices.Value.Records)
{
    Console.WriteLine($"Invoice {count++}: {invoice.InvoiceId}");
    Console.WriteLine($"Company Name: {invoice.Customer.CompanyName}");
    Console.WriteLine($"Outstanding Balance: {invoice.OutstandingBalanceAmount}");
}

To format the outstanding balance to print like $0.00, replace with Console.WriteLine($"Outstanding Balance: {string.Format("{0:C}", invoice.OutstandingBalanceAmount)}");.

Step 5: Examine Results

If everything is working when you build or debug your program, you will see the query results print to the console with the following format:

Invoice: 00000000-0000-0000-0000-000000000000
Company Name: CompanyNameHere
Outstanding Balance: $0.00
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
2023.13.37 0 3/31/2023
2023.11.28 70 3/22/2023
2023.7.8 120 2/20/2023
2023.7.7 121 2/16/2023
2023.5.21 115 2/7/2023
2023.4.0 147 1/30/2023
2023.3.18 137 1/23/2023
2023.1.3 158 1/9/2023
2022.37.24 276 9/20/2022
2022.35.5 814 9/6/2022
2022.33.14 287 8/23/2022
2022.26.12 301 7/11/2022
2022.17.35 303 5/23/2022
2022.15.31 321 4/19/2022
2022.14.30 587 4/11/2022
2022.13.29 367 3/31/2022
2022.11.60 306 3/21/2022
2022.10.63 323 3/14/2022
2022.9.56 301 3/10/2022
2022.9.18 309 3/2/2022
2022.9.6 298 3/2/2022
2022.7.31 312 2/16/2022
2022.6.50 313 2/14/2022
2022.6.49 505 2/11/2022
2022.6.48 331 2/10/2022
2022.6.42 313 2/10/2022
2022.5.19 311 2/9/2022
2022.4.32 318 1/31/2022
2022.3.32 322 1/20/2022
2022.2.63 325 1/19/2022
2021.39.692 181 1/7/2022
2021.39.691 184 1/6/2022
2021.39.690 186 12/28/2021
1.0.0 341 1/19/2022

# 2023.13.37
       
           For full patch notes see [Patch Notes](https://medium.com/lockstep-developer/tagged/patch-notes) on the [Lockstep Developer website](https://developer.lockstep.io/)