The SDK and supporting files are provided with SAP Business One. This article focuses on a simple .Net console application that will list all companies setup in Business One. First ensure that you have located the following DLL file SAPbobsCOM90.dll. You will need to add a refernce to this DDL in your .Net project.
Open Visual Studios and create a new Console Application. From the Project menu click Add Reference. Browse for SAPbobsCOM90.dll.
The API requires authentication, which means you will first need to login to a company.
Listing 1
SAPbobsCOM.Company comp = new SAPbobsCOM.Company();
comp.Server = "server ip:30015";
comp.CompanyDB = "db name";
comp.DbUserName = "db username";
comp.DbPassword = "db password";
comp.UserName = "username";
comp.Password = "password";
comp.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
comp.Connect();
Listing 1 above shows the authentication and connection code. Notice that the DbServerType is set to HANADB. If you are using MSSQL, you will need to change the server type to dst_MSSQL*.
Errors are handled by the GetLastError() method of the Company object. This method accpets two paramaters, which must be passed by reference. The first argument is errCode, which must be of type int and the second is errMsg which must be of type string.
Listing 2
int errCode = 0;
string errMsg = "";
comp.GetLastError(out errCode, out errMsg);
if (errCode < 0)
{
Console.WriteLine(errMsg);
}
If errCode is below 0, this means an error has occured. You should then check errMsg to determine what the error was. If errCode is 0 then no error occured.
If the connection was successful, you can then call the GetCompanyList() method on the comp object to get a Recordset containing all companies.
Listing 3
SAPbobsCOM.Recordset result = comp.GetCompanyList();
while (!result.EoF)
{
Console.WriteLine(result.Fields.Item(0).Value);
result.MoveNext();
}
-
Stock Transfer Part 2
In the previous article I exaplined how to transfer stock between warehouses and bin enabled warehouses. In this article, I discuss how to transfer batch enabled items.
07 August 2020 - 4242 views -
Stock Transfer Part 1
The SAP B1 Service Layer provides an API to move stock between warehouses. This article explains the construction of the JSON payload data that is posted to the StockTransfers API.
12 December 2019 - 6692 views -
php-sapb1 Library Documentation v1
A simple and easy to use PHP library for SAP Business One Service Layer API.
16 August 2019 - 8711 views -
node-sapb1 Library Documentation v1
This article provides documentation on the SAPb1 NodeJs library.
01 August 2019 - 8480 views -
PHP Service Layer Example Part 2
This article is part 2 of PHP Service Layer Example. In the previous article, I explained how to initiate an authentication request to get a Service Layer session id and route id. In this article we use these details to execute a request to retrieve a list of business partners.
25 January 2018 - 10666 views -
PHP Service Layer Example Part 1
This article explains how to get connected to the Service Layer using PHP.
09 January 2018 - 14301 views -
Introduction To SAP Business One Service Layer
An introduction to the SAP Business One Service Layer.
08 December 2017 - 10594 views