LockstepSdk 2023.28.10

There is a newer version of this package available.
See the version list below for details.
dotnet add package LockstepSdk --version 2023.28.10                
NuGet\Install-Package LockstepSdk -Version 2023.28.10                
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.28.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LockstepSdk --version 2023.28.10                
#r "nuget: LockstepSdk, 2023.28.10"                
#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.28.10

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

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 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
2023.35.16 1,509 8/31/2023
2023.35.14 264 8/30/2023
2023.28.10 412 7/13/2023
2023.17.21 721 4/27/2023
2023.13.37 459 3/31/2023
2023.11.28 497 3/22/2023
2023.7.8 616 2/20/2023
2023.7.7 523 2/16/2023
2023.5.21 503 2/7/2023
2023.4.0 528 1/30/2023
2023.3.18 529 1/23/2023
2023.1.3 570 1/9/2023
2022.37.24 656 9/20/2022
2022.35.5 2,746 9/6/2022
2022.33.14 669 8/23/2022
2022.26.12 700 7/11/2022
2022.17.35 697 5/23/2022
2022.15.31 694 4/19/2022
2022.14.30 981 4/11/2022
2022.13.29 780 3/31/2022
2022.11.60 680 3/21/2022
2022.10.63 706 3/14/2022
2022.9.56 687 3/10/2022
2022.9.18 686 3/2/2022
2022.9.6 645 3/2/2022
2022.7.31 665 2/16/2022
2022.6.50 693 2/14/2022
2022.6.49 885 2/11/2022
2022.6.48 686 2/10/2022
2022.6.42 663 2/10/2022
2022.5.19 643 2/9/2022
2022.4.32 707 1/31/2022
2022.3.32 702 1/20/2022
2022.2.63 699 1/19/2022
2021.39.692 546 1/7/2022
2021.39.691 509 1/6/2022
2021.39.690 530 12/28/2021
1.0.0 910 1/19/2022

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