PHPackages                             codebar-ag/laravel-bexio - 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. [API Development](/categories/api)
4. /
5. codebar-ag/laravel-bexio

ActiveLibrary[API Development](/categories/api)

codebar-ag/laravel-bexio
========================

Bexio integration with Laravel

v13.6.0(1mo ago)44.0k3[6 issues](https://github.com/codebar-ag/laravel-bexio/issues)[1 PRs](https://github.com/codebar-ag/laravel-bexio/pulls)MITPHPPHP 8.2.\*|8.3.\*|8.4.\*CI failing

Since Dec 2Pushed 1mo agoCompare

[ Source](https://github.com/codebar-ag/laravel-bexio)[ Packagist](https://packagist.org/packages/codebar-ag/laravel-bexio)[ Docs](https://github.com/codebar-ag/laravel-bexio)[ RSS](/packages/codebar-ag-laravel-bexio/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (38)Versions (37)Used By (0)

[![](https://camo.githubusercontent.com/ca9259fa1cff12c187b57f4526f3cdb3dec805179c1d81f68e0df7f05471c024/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230426578696f2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d636f64656261722d61672532466c61726176656c2d626578696f267061747465726e3d63697263756974426f617264267374796c653d7374796c655f32266465736372697074696f6e3d412b4c61726176656c2b426578696f2b696e746567726174696f6e2e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313530707826696d616765733d686f6d65267769647468733d35303026686569676874733d353030)](https://camo.githubusercontent.com/ca9259fa1cff12c187b57f4526f3cdb3dec805179c1d81f68e0df7f05471c024/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230426578696f2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d636f64656261722d61672532466c61726176656c2d626578696f267061747465726e3d63697263756974426f617264267374796c653d7374796c655f32266465736372697074696f6e3d412b4c61726176656c2b426578696f2b696e746567726174696f6e2e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313530707826696d616765733d686f6d65267769647468733d35303026686569676874733d353030)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2f6991ef133efa7816a2f992ac0979e1d3186473f3cf300487c9955b9befef02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64656261722d61672f6c61726176656c2d626578696f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codebar-ag/laravel-bexio)[![Total Downloads](https://camo.githubusercontent.com/cf83423cf6dd3e95cc4d267afb64bf237bd7f24e78ff4bdb8288e42d02f73e99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64656261722d61672f6c61726176656c2d626578696f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codebar-ag/laravel-bexio)[![GitHub-Tests](https://github.com/codebar-ag/laravel-bexio/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/codebar-ag/laravel-bexio/actions/workflows/run-tests.yml)[![GitHub Code Style](https://github.com/codebar-ag/laravel-bexio/actions/workflows/fix-php-code-style-issues.yml/badge.svg?branch=main)](https://github.com/codebar-ag/laravel-bexio/actions/workflows/fix-php-code-style-issues.yml)[![PHPStan](https://github.com/codebar-ag/laravel-bexio/actions/workflows/phpstan.yml/badge.svg)](https://github.com/codebar-ag/laravel-bexio/actions/workflows/phpstan.yml)[![Dependency Review](https://github.com/codebar-ag/laravel-bexio/actions/workflows/dependency-review.yml/badge.svg)](https://github.com/codebar-ag/laravel-bexio/actions/workflows/dependency-review.yml)

This package was developed to give you a quick start to the Bexio API.

📑 Table of Contents
-------------------

[](#-table-of-contents)

- [What is Bexio?](#-what-is-bexio)
- [Requirements](#-requirements)
- [Authentication](#authentication)
- [Installation](#%EF%B8%8F-installation)
- [Authentication Setup](#-authentication-setup)
    - [Environment Variables](#environment-variables)
    - [Single Tenant Authentication](#single-tenant-authentication)
        - [Token Authentication](#token-authentication)
        - [OAuth Authentication](#oauth-authentication)
        - [OAuth Flow](#oauth-flow)
        - [OAuth Callback Response](#oauth-callback-response)
    - [Multi-Tenant Authentication](#multi-tenant-authentication)
        - [Token Authentication (Multi-Tenant)](#token-authentication-multi-tenant)
        - [OAuth Authentication (Multi-Tenant)](#oauth-authentication-multi-tenant)
    - [Custom OAuth Authentication Validation (Optional)](#custom-oauth-authentication-validation-optional)
    - [Available OAuth Scopes](#available-oauth-scopes)
- [Advanced Configuration](#%EF%B8%8F-advanced-configuration)
    - [Custom Cache Store](#custom-cache-store)
    - [Custom Route Configuration](#custom-route-configuration)
- [Basic Usage](#basic-usage)
    - [Responses](#responses)
    - [Enums](#enums)
    - [DTOs](#dtos)
    - [Examples](#examples)
- [API Reference](#api-reference)
    - [Accounts](#accounts)
    - [Bank Accounts](#bank-accounts)
    - [Business Years](#business-years)
    - [Calendar Years](#calendar-years)
    - [Company Profiles](#company-profiles)
    - [Additional Addresses](#additional-addresses)
    - [Contact Groups](#contact-groups)
    - [Contact Relations](#contact-relations)
    - [Contacts](#contacts)
    - [Contact Sectors](#contact-sectors)
    - [Countries](#countries)
    - [Currencies](#currencies)
    - [Files](#files)
    - [Iban Payments](#iban-payments)
    - [Invoices](#invoices)
    - [Item Positions](#item-positions)
    - [Items](#items)
    - [Quotes](#quotes)
    - [Languages](#languages)
    - [Manual Entries](#manual-entries)
    - [Notes](#notes)
    - [Payments](#payments)
    - [Qr Payments](#qr-payments)
    - [Reports](#reports)
    - [Salutations](#salutations)
    - [Taxes](#taxes)
    - [Titles](#titles)
    - [VAT Periods](#vat-periods)
- [Testing](#-testing)
- [Changelog](#-changelog)
- [Contributing](#%EF%B8%8F-contributing)
    - [Code Style](#code-style)
- [Security Vulnerabilities](#%EF%B8%8F-security-vulnerabilities)
- [Credits](#-credits)
- [License](#-license)

💡 What is Bexio?
----------------

[](#-what-is-bexio)

Bexio is a cloud-based simple business software for the self-employed, small businesses and startups.

🛠 Requirements
--------------

[](#-requirements)

PackagePHPLaravelv13.0.0 (alpha)^8.3 - ^8.5^12.xv12.0.0^8.2 - ^8.412.xv11.0.0^8.2 - ^8.311.xv1.0.0^8.210.xAuthentication
--------------

[](#authentication)

The package supports multiple authentication methods for both single-tenant and multi-tenant applications:

MethodSupportedAPI token✅OAuth✅⚙️ Installation
---------------

[](#️-installation)

You can install the package via composer:

```
composer require codebar-ag/laravel-bexio
```

Optionally, you can publish the config file with:

```
php artisan vendor:publish --provider="CodebarAg\Bexio\BexioServiceProvider" --tag="bexio-config"
```

🔐 Authentication Setup
----------------------

[](#-authentication-setup)

### Environment Variables

[](#environment-variables)

Add the following environment variables to your `.env` file:

```
# For Token Authentication
BEXIO_API_TOKEN=your_api_token_here

# For OAuth Authentication
BEXIO_OAUTH_CLIENT_ID=your_client_id_here
BEXIO_OAUTH_CLIENT_SECRET=your_client_secret_here
BEXIO_OAUTH_SCOPES=accounting,contact_show

# Optional: Custom cache store for OAuth tokens
BEXIO_CACHE_STORE=redis

# Optional: Redirect URL after successful OAuth authentication (will redirect to / by default)
BEXIO_REDIRECT_URL=/dashboard
```

You can retrieve your API token or OAuth credentials from your [Bexio Developer Dashboard](https://delveloper.bexio.com).

For OAuth credentials, you'll need to register your application in the Bexio Developer Portal.

🚀 Usage
-------

[](#-usage)

### Single Tenant Authentication

[](#single-tenant-authentication)

For applications that only need to authenticate with one Bexio account:

#### Token Authentication

[](#token-authentication)

```
use CodebarAg\Bexio\BexioConnector;
use CodebarAg\Bexio\Dto\OAuthConfiguration\ConnectWithToken;

// Using environment configuration
$connector = new BexioConnector(new ConnectWithToken());

// Or with explicit token
$connector = new BexioConnector(new ConnectWithToken(token: 'your-specific-token'));
```

#### OAuth Authentication

[](#oauth-authentication)

```
use CodebarAg\Bexio\BexioConnector;
use CodebarAg\Bexio\Dto\OAuthConfiguration\ConnectWithOAuth;

// Using environment configuration
$connector = new BexioConnector(new ConnectWithOAuth());

// Or with explicit configuration
$connector = new BexioConnector(new ConnectWithOAuth(
    client_id: 'your_client_id',
    client_secret: 'your_client_secret',
    redirect_uri: 'https://yourapp.com/bexio/callback',
    scopes: ['openid', 'profile', 'email', 'accounting']
));
```

#### OAuth Flow

[](#oauth-flow)

The package provides built-in routes for OAuth authentication:

1. **Redirect to Bexio**: `/bexio/redirect`
2. **OAuth Callback**: `/bexio/callback`

You can customize the route prefix and middleware in your config file:

```
// config/bexio.php
'route_prefix' => 'custom-bexio-prefix',

// Add custom middleware to OAuth routes (in addition to 'web' middleware)
'route_middleware' => ['auth', 'verified'],
```

#### OAuth Callback Response

[](#oauth-callback-response)

After the OAuth callback is processed, the user will be redirected to the URL specified in your configuration (`config('bexio.redirect_url')` or `/` by default) with flash session data indicating the result:

**Success Response:**

```
// When OAuth authentication is successful
session()->get('bexio_oauth_success'); // true
session()->get('bexio_oauth_message'); // 'Successfully authenticated with Bexio.'
```

**Error Responses:**

```
// When user rejects authorization or OAuth returns an error
session()->get('bexio_oauth_success'); // false
session()->get('bexio_oauth_message'); // 'OAuth authorization failed: access_denied'

// When required parameters (code or state) are missing
session()->get('bexio_oauth_success'); // false
session()->get('bexio_oauth_message'); // 'Missing required parameters: code or state.'
```

**Handling the callback in your controller:**

```
