LockstepSdk 2023.35.16
dotnet add package LockstepSdk --version 2023.35.16
NuGet\Install-Package LockstepSdk -Version 2023.35.16
<PackageReference Include="LockstepSdk" Version="2023.35.16" />
paket add LockstepSdk --version 2023.35.16
#r "nuget: LockstepSdk, 2023.35.16"
// Install LockstepSdk as a Cake Addin #addin nuget:?package=LockstepSdk&version=2023.35.16 // Install LockstepSdk as a Cake Tool #tool nuget:?package=LockstepSdk&version=2023.35.16
Lockstep SDK for C#
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 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. |
-
.NETStandard 2.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 6.0.2)
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,652 | 8/31/2023 |
2023.35.14 | 265 | 8/30/2023 |
2023.28.10 | 413 | 7/13/2023 |
2023.17.21 | 722 | 4/27/2023 |
2023.13.37 | 460 | 3/31/2023 |
2023.11.28 | 500 | 3/22/2023 |
2023.7.8 | 617 | 2/20/2023 |
2023.7.7 | 524 | 2/16/2023 |
2023.5.21 | 504 | 2/7/2023 |
2023.4.0 | 529 | 1/30/2023 |
2023.3.18 | 530 | 1/23/2023 |
2023.1.3 | 571 | 1/9/2023 |
2022.37.24 | 657 | 9/20/2022 |
2022.35.5 | 2,747 | 9/6/2022 |
2022.33.14 | 670 | 8/23/2022 |
2022.26.12 | 701 | 7/11/2022 |
2022.17.35 | 698 | 5/23/2022 |
2022.15.31 | 695 | 4/19/2022 |
2022.14.30 | 982 | 4/11/2022 |
2022.13.29 | 783 | 3/31/2022 |
2022.11.60 | 681 | 3/21/2022 |
2022.10.63 | 707 | 3/14/2022 |
2022.9.56 | 688 | 3/10/2022 |
2022.9.18 | 687 | 3/2/2022 |
2022.9.6 | 646 | 3/2/2022 |
2022.7.31 | 666 | 2/16/2022 |
2022.6.50 | 694 | 2/14/2022 |
2022.6.49 | 886 | 2/11/2022 |
2022.6.48 | 687 | 2/10/2022 |
2022.6.42 | 664 | 2/10/2022 |
2022.5.19 | 644 | 2/9/2022 |
2022.4.32 | 708 | 1/31/2022 |
2022.3.32 | 703 | 1/20/2022 |
2022.2.63 | 700 | 1/19/2022 |
2021.39.692 | 547 | 1/7/2022 |
2021.39.691 | 510 | 1/6/2022 |
2021.39.690 | 533 | 12/28/2021 |
1.0.0 | 911 | 1/19/2022 |
# 2023.35.16
For full patch notes see [Patch Notes](https://medium.com/lockstep-developer/tagged/patch-notes) on the [Lockstep Developer website](https://developer.lockstep.io/)