PHPackages                             ecourier/ecourier - 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. ecourier/ecourier

ActiveLibrary[API Development](/categories/api)

ecourier/ecourier
=================

PHP SDK for the eCourier API

v1.1.0(3w ago)0338↓83.3%1MITPHPPHP ^8.3CI passing

Since Jul 15Pushed 3w ago1 watchersCompare

[ Source](https://github.com/utecca/ecourier-php-sdk)[ Packagist](https://packagist.org/packages/ecourier/ecourier)[ RSS](/packages/ecourier-ecourier/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (1)

eCourier PHP SDK
================

[](#ecourier-php-sdk)

**A clean, modern PHP SDK for the [eCourier API](https://docs.ecourier.io), built with [Saloon](https://docs.saloon.dev).**

[![Tests](https://github.com/utecca/ecourier-php-sdk/actions/workflows/tests.yml/badge.svg)](https://github.com/utecca/ecourier-php-sdk/actions/workflows/tests.yml)[![PHP](https://camo.githubusercontent.com/ef0054230522e542bc1f908ac005c6c75888dea255bac910f9015e12095e31d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e332d626c7565)](https://www.php.net)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

Send and receive electronic documents, such as invoices and credit notes, from your PHP application. The SDK wraps the full [eCourier REST API v1](https://docs.ecourier.io/api-reference/v1) and gives you typed responses, automatic pagination, and clear exceptions for every error case.

---

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

[](#installation)

```
composer require ecourier/ecourier
```

**Requirements:** PHP 8.3+

---

Getting Started
---------------

[](#getting-started)

Instantiate the connector with your API key. The key prefix determines the mode: `pk_test_` for test, `pk_live_` for production.

```
use Ecourier\EcourierConnector;

// Test mode
$ecourier = new EcourierConnector(apiKey: 'pk_test_your_key_here');

// Production
$ecourier = new EcourierConnector(apiKey: 'pk_live_your_key_here');
```

All requests are authenticated automatically via `Authorization: Bearer` — you never touch headers yourself.

---

Resources
---------

[](#resources)

The SDK is organized into four resources, accessible as methods on the connector.

ResourceMethodCoversCompanies`$ecourier->companies()`List, create, update, delete, and inspect companiesDocuments`$ecourier->documents()`Send, receive, and inspect documents, such as invoices and credit notesParticipants`$ecourier->participants()`List, create, update, delete, and inspect participantsLookup`$ecourier->lookup()`Look up network participants by channel, scheme, and ID---

Companies
---------

[](#companies)

### List companies

[](#list-companies)

```
use Ecourier\Enums\Channel;

$companies = $ecourier->companies()
    ->list(
        channel: Channel::Peppol,
        country: 'DK',
        signed: false,
        perPage: 50,
    )
    ->collect();
```

### Get a company

[](#get-a-company)

```
$company = $ecourier->companies()->find('comp_01abc');

echo $company->name;      // Acme Danmark A/S
echo $company->companyNo; // 12345678
echo $company->mode;      // Mode::Live
```

`find()` returns a typed `CompanyData` DTO. If you need the raw `Response` object instead, use `get()`:

```
$response = $ecourier->companies()->get('comp_01abc');

$response->status(); // 200
$response->json();   // raw array
```

### Create a company

[](#create-a-company)

```
use Ecourier\Data\CompanyAuthorisationSignerData;
use Ecourier\Data\CreateCompanyData;

$company = $ecourier->companies()->create(new CreateCompanyData(
    name: 'Acme Danmark A/S',
    country: 'DK',
    companyNo: '12345678',
    signer: new CompanyAuthorisationSignerData(
        firstName: 'Ada',
        lastName: 'Lovelace',
        title: 'CEO',
    ),
));
```

### Update a company

[](#update-a-company)

```
$company = $ecourier->companies()->update(
    company: '0101knwp96k3ggvkra831yrd74zh',
    name: 'Acme Danmark A/S',
);
```

### Delete a company

[](#delete-a-company)

```
$response = $ecourier->companies()->delete('0101knwp96k3ggvkra831yrd74zh');

$response->status(); // 204
```

---

Documents
---------

[](#documents)

Documents are the core of eCourier — they represent invoices and credit notes moving through the network.

### Send a document as JSON

[](#send-a-document-as-json)

Build a typed `InvoiceDocumentData` payload and submit it to a specific channel. eCourier converts it to the correct XML schema automatically.

```
use Ecourier\Data\Invoice\InvoiceDocumentData;
use Ecourier\Data\Invoice\InvoiceLineData;
use Ecourier\Data\Invoice\InvoicePartyData;
use Ecourier\Data\Invoice\InvoiceTotalsData;
use Ecourier\Data\Invoice\ParticipantIdentifier;
use Ecourier\Enums\Channel;
use Ecourier\Enums\Currency;
use Ecourier\Enums\DocumentType;
use Ecourier\Enums\IdentifierScheme;

$invoice = new InvoiceDocumentData(
    type: DocumentType::Invoice,
    id: 'INV-2024-001',
    issueDate: '2024-06-01',
    currency: Currency::DKK,
    supplier: new InvoicePartyData(
        participant: new ParticipantIdentifier(IdentifierScheme::DK_CVR, '12345678'),
    ),
    customer: new InvoicePartyData(
        participant: new ParticipantIdentifier(IdentifierScheme::DK_CVR, '87654321'),
    ),
    lines: [
        new InvoiceLineData(id: '1'),
    ],
    totals: new InvoiceTotalsData(
        subtotalAmount: '1000.00',
        taxAmount: '250.00',
        totalAmount: '1250.00',
    ),
);

$document = $ecourier->documents()->sendJson(Channel::Peppol, $invoice);

echo $document->id;             // 01kmkdaf55vrrecfy70180tpr6
echo $document->e2eMessageUuid; // ddc3b3ef-cbd4-4630-9d65-896b3e1abc61
```

> **Note:** `sendJson()` returns the accepted document ID and network message UUID. Use webhooks or poll `find()` to track delivery.

### Send a document as raw XML

[](#send-a-document-as-raw-xml)

If you need full control over the XML schema, send the raw UBL document directly. All routing headers are required.

```
use Ecourier\Enums\Channel;
use Ecourier\Enums\IdentifierScheme;

$xml =
