B1SLayer 2.0.0-pre2

Prefix Reserved
This is a prerelease version of B1SLayer.
There is a newer version of this package available.
See the version list below for details.
dotnet add package B1SLayer --version 2.0.0-pre2                
NuGet\Install-Package B1SLayer -Version 2.0.0-pre2                
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="B1SLayer" Version="2.0.0-pre2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add B1SLayer --version 2.0.0-pre2                
#r "nuget: B1SLayer, 2.0.0-pre2"                
#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 B1SLayer as a Cake Addin
#addin nuget:?package=B1SLayer&version=2.0.0-pre2&prerelease

// Install B1SLayer as a Cake Tool
#tool nuget:?package=B1SLayer&version=2.0.0-pre2&prerelease                

B1SLayer

B1SLayer Downloads

A lightweight SAP Business One Service Layer client for .NET

B1SLayer aims to provide:

  • Fluent and easy Service Layer requests
  • Automatic session management
  • Automatic retry of failed requests

How to use it

Firstly I highly recommend reading my blog post on SAP Community where I go into more details, but here's a couple examples of what's possible (but not limited to) with B1SLayer:

/* The connection object. All Service Layer requests and the session management are handled by this object
 * and therefore only one instance per company/user should be used across the entire application.
 * If you want to connect to multiple databases or use different users, you will need multiple instances.
 * There's no need to manually Login! The session is managed automatically and renewed whenever necessary.
 */
var serviceLayer = new SLConnection("https://sapserver:50000/b1s/v1", "CompanyDB", "manager", "12345");

// Performs a GET on /Orders(823) and deserializes the result in a custom model class
var order = await serviceLayer.Request("Orders", 823).GetAsync<MyOrderModel>();

// Performs a GET on /BusinessPartners with query string and header parameters supported by Service Layer
// The result is deserialized in a List of a custom model class
var bpList = await serviceLayer.Request("BusinessPartners")
    .Filter("startswith(CardCode, 'c')")
    .Select("CardCode, CardName")
    .OrderBy("CardName")
    .WithPageSize(50)
    .WithCaseInsensitive()
    .GetAsync<List<MyBusinessPartnerModel>>();

// Performs a GET on /AlternateCatNum specifying the record through a composite primary key
var altCatNum = await serviceLayer
    .Request("AlternateCatNum(ItemCode='A00001',CardCode='C00001',Substitute='BP01')")
    .GetAsync<MyAltCatModel>();

// Performs multiple GET requests on /Items until all entities in the database are obtained
// The result is an IList of your custom model class (unwrapped from the 'value' array)
var allItemsList = await serviceLayer.Request("Items").GetAllAsync<MyItemModel>();

// Performs a POST on /Orders with the provided object as the JSON body, 
// creating a new order and deserializing the created order in a custom model class
var createdOrder = await serviceLayer.Request("Orders").PostAsync<MyOrderModel>(myNewOrderObject);

// Performs a PATCH on /BusinessPartners('C00001'), updating the CardName of the Business Partner
await serviceLayer.Request("BusinessPartners", "C00001")
    .PatchAsync(new { CardName = "Updated BP name" });

// Performs a PATCH on /ItemImages('A00001'), adding or updating the item image
await serviceLayer.Request("ItemImages", "A00001")
    .PatchWithFileAsync(@"C:\ItemImages\A00001.jpg");

// Performs a POST on /Attachments2 with the provided file as the attachment
var attachmentEntry = await serviceLayer.PostAttachmentAsync(@"C:\files\myfile.pdf");

// Batch requests! Performs multiple operations in SAP in a single HTTP request
var req1 = new SLBatchRequest(
    HttpMethod.Post, // HTTP method
    "BusinessPartners", // resource
    new { CardCode = "C00001", CardName = "I'm a new BP" }) // object to be sent as the JSON body
    .WithReturnNoContent(); // Adds the header "Prefer: return-no-content" to the request

var req2 = new SLBatchRequest(HttpMethod.Patch,
    "BusinessPartners('C00001')",
    new { CardName = "This is my updated name" });

var req3 = new SLBatchRequest(HttpMethod.Delete, "BusinessPartners('C00001')");

HttpResponseMessage[] batchResult = await serviceLayer.PostBatchAsync(req1, req2, req3);

// Performs a POST on /Logout, ending the current session
await serviceLayer.LogoutAsync();

Get it on NuGet

PM> Install-Package B1SLayer

dotnet add package B1SLayer

Special thanks

B1Slayer is based and depends on the awesome Flurl library, which I highly recommend checking out. Thanks, Todd!

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 (2)

Showing the top 2 NuGet packages that depend on B1SLayer:

Package Downloads
LAB1-ServiceLayer

LAB1

ServiceLayerFluentMigrator

API to create User Table in SAP Business One using a fluent interface

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 729 9/5/2024
2.0.0-pre3 100 7/3/2024
2.0.0-pre2 493 5/31/2024
2.0.0-pre1 523 5/10/2024
1.3.2 17,336 8/10/2023
1.3.1 517 7/27/2023
1.3.0 5,797 1/20/2023
1.2.1 8,619 10/26/2022
1.2.0 11,363 3/23/2022
1.1.0 6,505 7/22/2021
1.0.3 1,686 4/16/2021
1.0.2 413 1/25/2021
1.0.1 377 1/20/2021
1.0.0 462 1/19/2021