sap.businessone
ballerinax/sap.businessone Ballerina library
Ballerina SAP Business One Connector
ballerinax/sap.businessone is a generic HTTP client for the SAP Business One Service Layer (OData V3).
It wraps ballerina/http:Client and transparently manages the Service Layer's session-based authentication:
- Logs in with the configured company database, user name, and password (
POST /Login). - Tracks the
B1SESSIONandROUTEIDcookies through the HTTP client's cookie store, so load-balanced Service Layer deployments work without extra configuration. - When a request fails with HTTP 401 (session expired — the Service Layer default timeout is 30 minutes), the client re-logs in and replays the request once.
->logout()ends the session explicitly.
This package is the transport used by the ballerinax/sap.businessone.* module connectors (e.g. sap.businessone.sales, sap.businessone.inventory). Use it directly when you need an endpoint or query shape the module connectors don't expose.
Quickstart
import ballerinax/sap.businessone; public function main() returns error? { businessone:Client b1 = check new ("https://localhost:50000/b1s/v1", { companyDb: "SBODEMOUS", username: "manager", password: "manager-password" }); json orders = check b1->/Orders(headers = (), targetType = json, \$top = 5); check b1->logout(); }
Setup
Any SAP Business One on-premise installation (or B1 Cloud) with the Service Layer component installed exposes the endpoint at https://<host>:50000/b1s/v1. A valid B1 user with appropriate license and authorizations is required.
Clients
sap.businessone: Client
The sap.businessone client provides the capability for initiating contact with the SAP Business One
Service Layer. The API it provides includes the functions for the standard HTTP methods
Authentication is session based: the client logs in to the Service Layer with the configured company database, user name, and password, and transparently re-logs in and replays the request once when the session expires (HTTP 401)
Constructor
Gets invoked to initialize the client. During initialization, the configurations provided through the config
record is used to determine which type of additional behaviours are added to the endpoint (e.g.,
security, circuit breaking). The Service Layer session (B1SESSION and ROUTEID cookies) is captured
from the login response and attached to every request by the client itself
init (string url, SessionConfig session, ClientConfiguration config)- url string - URL of the target Service Layer endpoint (e.g.
https://host:50000/b1s/v1)
- session SessionConfig - The Service Layer session credentials
- config ClientConfiguration {} - The configurations to be used when initializing the
client
post
function post(string path, RequestMessage message, map<string|string[]>? headers, string? mediaType, typedesc<TargetType> targetType) returns targetType|ClientErrorThe Client.post() function can be used to send HTTP POST requests to the SAP Business One Service Layer
Parameters
- path string - Resource path
- message RequestMessage - An HTTP outbound request or any allowed payload
- mediaType string? (default ()) - The MIME type header of the request entity
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
put
function put(string path, RequestMessage message, map<string|string[]>? headers, string? mediaType, typedesc<TargetType> targetType) returns targetType|ClientErrorThe Client.put() function can be used to send HTTP PUT requests to the SAP Business One Service Layer
Parameters
- path string - Resource path
- message RequestMessage - An HTTP outbound request or any allowed payload
- mediaType string? (default ()) - The MIME type header of the request entity
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
patch
function patch(string path, RequestMessage message, map<string|string[]>? headers, string? mediaType, typedesc<TargetType> targetType) returns targetType|ClientErrorThe Client.patch() function can be used to send HTTP PATCH requests to the SAP Business One Service Layer
Parameters
- path string - Resource path
- message RequestMessage - An HTTP outbound request or any allowed payload
- mediaType string? (default ()) - The MIME type header of the request entity
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
delete
function delete(string path, RequestMessage message, map<string|string[]>? headers, string? mediaType, typedesc<TargetType> targetType) returns targetType|ClientErrorThe Client.delete() function can be used to send HTTP DELETE requests to the SAP Business One Service Layer
Parameters
- path string - Resource path
- message RequestMessage (default ()) - An optional HTTP outbound request message or any allowed payload
- mediaType string? (default ()) - The MIME type header of the request entity
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
head
The Client.head() function can be used to send HTTP HEAD requests to the SAP Business One Service Layer
Parameters
- path string - Resource path
Return Type
- Response|ClientError - The response or a
sap.businessone:ClientErrorif failed to establish the communication with the upstream server
get
function get(string path, map<string|string[]>? headers, typedesc<TargetType> targetType) returns targetType|ClientErrorThe Client.get() function can be used to send HTTP GET requests to the SAP Business One Service Layer
Parameters
- path string - Request path
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
options
function options(string path, map<string|string[]>? headers, typedesc<TargetType> targetType) returns targetType|ClientErrorThe Client.options() function can be used to send HTTP OPTIONS requests to the SAP Business One Service Layer
Parameters
- path string - Request path
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
logout
function logout() returns ClientError?Ends the current Service Layer session
Return Type
- ClientError? - A
sap.businessone:ClientErrorif the logout failed
post [http:PathParamType... path]
function post [http:PathParamType... path](RequestMessage message, map<string|string[]>? headers, string? mediaType, typedesc<TargetType> targetType, *QueryParams params) returns targetType|ClientErrorThe client resource function to send HTTP POST requests to the SAP Business One Service Layer
Parameters
- message RequestMessage - An HTTP outbound request or any allowed payload
- mediaType string? (default ()) - The MIME type header of the request entity
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
- params *QueryParams - The query parameters
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
put [http:PathParamType... path]
function put [http:PathParamType... path](RequestMessage message, map<string|string[]>? headers, string? mediaType, typedesc<TargetType> targetType, *QueryParams params) returns targetType|ClientErrorThe client resource function to send HTTP PUT requests to the SAP Business One Service Layer
Parameters
- message RequestMessage - An HTTP outbound request or any allowed payload
- mediaType string? (default ()) - The MIME type header of the request entity
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
- params *QueryParams - The query parameters
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
patch [http:PathParamType... path]
function patch [http:PathParamType... path](RequestMessage message, map<string|string[]>? headers, string? mediaType, typedesc<TargetType> targetType, *QueryParams params) returns targetType|ClientErrorThe client resource function to send HTTP PATCH requests to the SAP Business One Service Layer
Parameters
- message RequestMessage - An HTTP outbound request or any allowed payload
- mediaType string? (default ()) - The MIME type header of the request entity
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
- params *QueryParams - The query parameters
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
delete [http:PathParamType... path]
function delete [http:PathParamType... path](RequestMessage message, map<string|string[]>? headers, string? mediaType, typedesc<TargetType> targetType, *QueryParams params) returns targetType|ClientErrorThe client resource function to send HTTP DELETE requests to the SAP Business One Service Layer
Parameters
- message RequestMessage (default ()) - An optional HTTP outbound request or any allowed payload
- mediaType string? (default ()) - The MIME type header of the request entity
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
- params *QueryParams - The query parameters
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
head [http:PathParamType... path]
function head [http:PathParamType... path](map<string|string[]>? headers, *QueryParams params) returns Response|ClientErrorThe client resource function to send HTTP HEAD requests to the SAP Business One Service Layer
Parameters
- params *QueryParams - The query parameters
Return Type
- Response|ClientError - The response or a
sap.businessone:ClientErrorif failed to establish the communication with the upstream server
get [http:PathParamType... path]
function get [http:PathParamType... path](map<string|string[]>? headers, typedesc<TargetType> targetType, *QueryParams params) returns targetType|ClientErrorThe client resource function to send HTTP GET requests to the SAP Business One Service Layer
Parameters
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
- params *QueryParams - The query parameters
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
options [http:PathParamType... path]
function options [http:PathParamType... path](map<string|string[]>? headers, typedesc<TargetType> targetType, *QueryParams params) returns targetType|ClientErrorThe client resource function to send HTTP OPTIONS requests to the SAP Business One Service Layer
Parameters
- targetType typedesc<TargetType> (default <>) - HTTP response or
anydata, which is expected to be returned after data binding
- params *QueryParams - The query parameters
Return Type
- targetType|ClientError - The response or the payload (if the
targetTypeis configured) or asap.businessone:ClientErrorif failed to establish the communication with the upstream server or a data binding failure
Records
sap.businessone: SessionConfig
SAP Business One Service Layer session credentials
Fields
- companyDb string - The company database (schema) to connect to
- username string - SAP Business One user code
- password string - SAP Business One user password
Union types
sap.businessone: TargetType
TargetType
The sap.businessone client return type for the HTTP client actions
Simple name reference types
sap.businessone: ClientError
ClientError
Defines the possible client error types
sap.businessone: LoginFailure
LoginFailure
Represents an error, which occurred while logging in to the SAP Business One Service Layer
Import
import ballerinax/sap.businessone;Metadata
Released date: 6 days ago
Version: 1.0.1
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.13.0
GraalVM compatible: Yes
Pull count
Total: 1362
Current verison: 304
Weekly downloads
Keywords
Name/SAP Business One
Area/ERP & Business Operations
Vendor/SAP
Cost/Paid
Type/Connector
SAP Business One
Service Layer
OData
ERP
Contributors