PHPackages                             blockshiftnetwork/sapb1-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. blockshiftnetwork/sapb1-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

blockshiftnetwork/sapb1-client
==============================

A robust, production-grade Laravel package for SAP Business One HTTP integration, supporting both OData and custom (non-OData) SAP Service Layer (SML) endpoints.

v0.2.3(1mo ago)2826↓28.6%[2 PRs](https://github.com/blockshiftnetwork/sapb1-client-laravel/pulls)MITPHPPHP ^8.3CI failing

Since Nov 5Pushed 1mo agoCompare

[ Source](https://github.com/blockshiftnetwork/sapb1-client-laravel)[ Packagist](https://packagist.org/packages/blockshiftnetwork/sapb1-client)[ Docs](https://github.com/blockshiftnetwork/sapb1-client-laravel)[ GitHub Sponsors](https://github.com/blockshiftnetwork)[ RSS](/packages/blockshiftnetwork-sapb1-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (26)Versions (13)Used By (0)

SAP B1 Client for Laravel
=========================

[](#sap-b1-client-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/db2c17f7b258574c83f0e7ba80d554da175dd13f022b0b35f08697ca5ee6b95e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626c6f636b73686966746e6574776f726b2f73617062312d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blockshiftnetwork/sapb1-client)[![Total Downloads](https://camo.githubusercontent.com/5b7084f2f716583e141d6a82c077f155416f2e208d8829bbaf07e8457871a67c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626c6f636b73686966746e6574776f726b2f73617062312d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blockshiftnetwork/sapb1-client)

A robust, production-grade Laravel package for SAP Business One HTTP integration, supporting multiple connections, fluent OData queries, and both standard and custom Service Layer endpoints.

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Laravel 11.x, 12.x, or 13.x

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require blockshiftnetwork/sapb1-client
```

Publish the config file:

```
php artisan vendor:publish --tag="sapb1-client-config"
```

Configuration
-------------

[](#configuration)

The package supports multiple named connections, each with its own server, credentials, and isolated session management. Add your credentials to `.env`:

```
# Default connection (optional, defaults to "service_layer")
SAPB1_DEFAULT_CONNECTION=service_layer

# Service Layer connection
SAPB1_SERVICE_LAYER_SERVER=https://your-sap-host.com/b1s/v1
SAPB1_SERVICE_LAYER_DATABASE=YOUR_COMPANY_DB
SAPB1_SERVICE_LAYER_USERNAME=manager
SAPB1_SERVICE_LAYER_PASSWORD=secret

# Gateway / Report Service connection
SAPB1_GATEWAY_SERVER=https://your-sap-gateway.com/rs/v1
SAPB1_GATEWAY_DATABASE=YOUR_COMPANY_DB
SAPB1_GATEWAY_USERNAME=manager
SAPB1_GATEWAY_PASSWORD=secret
```

The published config file (`config/sapb1-client.php`):

```
return [
    'default' => env('SAPB1_DEFAULT_CONNECTION', 'service_layer'),

    'connections' => [
        'service_layer' => [
            'server'     => env('SAPB1_SERVICE_LAYER_SERVER'),
            'database'   => env('SAPB1_SERVICE_LAYER_DATABASE'),
            'username'   => env('SAPB1_SERVICE_LAYER_USERNAME'),
            'password'   => env('SAPB1_SERVICE_LAYER_PASSWORD'),
            'cache_ttl'  => env('SAPB1_SERVICE_LAYER_CACHE_TTL', 1800),
            'pool_size'  => env('SAPB1_SERVICE_LAYER_POOL_SIZE', 1),
            'verify_ssl' => env('SAPB1_SERVICE_LAYER_VERIFY_SSL', true),
        ],

        'gateway' => [
            'server'     => env('SAPB1_GATEWAY_SERVER'),
            'database'   => env('SAPB1_GATEWAY_DATABASE'),
            'username'   => env('SAPB1_GATEWAY_USERNAME'),
            'password'   => env('SAPB1_GATEWAY_PASSWORD'),
            'cache_ttl'  => env('SAPB1_GATEWAY_CACHE_TTL', 1800),
            'pool_size'  => env('SAPB1_GATEWAY_POOL_SIZE', 1),
            'verify_ssl' => env('SAPB1_GATEWAY_VERIFY_SSL', true),
        ],
    ],
];
```

You can add as many connections as you need. Each connection maintains its own session independently.

Usage
-----

[](#usage)

### Multiple Connections

[](#multiple-connections)

The package works like Laravel's `DB::connection()`. The `SapB1` facade resolves to a connection manager that lazily creates client instances per named connection.

```
use BlockshiftNetwork\SapB1Client\Facades\SapB1;

// Use a specific connection
SapB1::connection('service_layer')->get('Items');
SapB1::connection('gateway')->post('PDFExport', ['DocEntry' => 1]);

// Shorthand macros (registered out of the box)
SapB1::serviceLayer()->get('Items');
SapB1::gateway()->post('PDFExport', ['DocEntry' => 1]);

// Calls without connection() go to the default connection
SapB1::get('Items');
```

### Fluent Query Builder

[](#fluent-query-builder)

The `query()` method returns a fluent builder for full CRUD operations on any SAP entity.

#### Listing records

[](#listing-records)

```
$response = SapB1::query('BusinessPartners')
    ->select('CardCode', 'CardName', 'Balance')
    ->where('CardType', 'cCustomer')
    ->where('Balance', '>', 0)
    ->orderBy('CardName')
    ->top(50)
    ->skip(10)
    ->get();

$customers = $response->json('value');
```

#### Finding a single record

[](#finding-a-single-record)

```
// String key
$response = SapB1::query('BusinessPartners')->find('C001');

// Numeric key
$response = SapB1::query('Orders')->find(123);

// With select
$response = SapB1::query('BusinessPartners')
    ->select('CardCode', 'CardName')
    ->find('C001');
```

#### Creating a record

[](#creating-a-record)

```
$response = SapB1::query('BusinessPartners')->create([
    'CardCode' => 'C2024',
    'CardName' => 'Acme Corp',
    'CardType' => 'cCustomer',
]);
```

#### Updating a record

[](#updating-a-record)

```
$response = SapB1::query('BusinessPartners')->update('C2024', [
    'CardName' => 'Acme Corporation',
]);
```

When updating documents with collection properties like `DocumentLines`, use `replaceCollections: true` to send the `B1S-ReplaceCollectionsOnPatch` header. Without it, SAP merges lines instead of replacing them.

```
$response = SapB1::query('Orders')->update(123, [
    'DocumentLines' => [
        ['ItemCode' => 'A001', 'Quantity' => 5],
        ['ItemCode' => 'A002', 'Quantity' => 3],
    ],
], replaceCollections: true);
```

#### Deleting a record

[](#deleting-a-record)

```
SapB1::query('BusinessPartners')->delete('C2024');
SapB1::query('Orders')->delete(123);
```

#### Query builder on named connections

[](#query-builder-on-named-connections)

All query builder methods work on any connection:

```
SapB1::gateway()->query('PDFExport')->create(['DocEntry' => 1]);

SapB1::serviceLayer()->query('Items')
    ->select('ItemCode', 'ItemName')
    ->where('ItemCode', 'startswith', 'A')
    ->top(20)
    ->get();
```

### OData Queries with Array Syntax

[](#odata-queries-with-array-syntax)

You can also pass raw OData parameters as an array:

```
$response = SapB1::odataQuery('Items', [
    '$filter'  => "ItemsGroupCode eq 100",
    '$orderby' => "ItemCode desc",
    '$top'     => 5,
]);

$items = $response->json('value');
```

Or build them with the standalone `ODataQuery` class:

```
use BlockshiftNetwork\SapB1Client\ODataQuery;

$query = (new ODataQuery())
    ->select('CardCode', 'CardName', 'Balance')
    ->where('CardType', '=', 'cCustomer')
    ->orWhere('CardName', 'contains', 'Acme Inc.')
    ->where('Balance', '>', 0)
    ->where('CreateDate', 'between', ['2023-01-01', '2023-12-31'])
    ->orderBy('CardName', 'desc')
    ->top(50)
    ->skip(10);

$response = SapB1::odataQuery('BusinessPartners', $query);
```

#### Supported Operators

[](#supported-operators)

The `where` and `orWhere` methods support these operators:

OperatorDescriptionExample`=`, `eq`Equal`->where('CardType', '=', 'cCustomer')``!=`, `ne`Not Equal`->where('Status', '!=', 'Inactive')``>`, `gt`Greater Than`->where('Balance', '>', 1000)``>=`, `ge`Greater Than or Equal`->where('Stock', '>=', 10)``where('DocTotal', '
