.NET SDK

Install and use EConnect.Psb: NuGet package, dependency injection, API interfaces and webhook validation for ASP.NET Core.

The .NET SDK (econnect-psb-dotnet) is the official C# client for the PSB REST API. The NuGet package EConnect.Psb provides typed interfaces for all API groups and supports dependency injection in ASP.NET Core.

Repositorygithub.com/theinvoicingcompany/econnect-psb-dotnetNuGetEConnect.PsbWebhook validationEConnect.Psb.AspNetCore.Mvc
Requirements
  • .NET Core 2.0 or higher, or .NET Framework 4.6.1+
Installation

Via the .NET CLI:

dotnet add package EConnect.Psb

Via Package Manager Console:

Install-Package EConnect.Psb

For webhook validation in ASP.NET Core MVC:

dotnet add package EConnect.Psb.AspNetCore.Mvc
Configuration with dependency injection

The recommended setup uses AddPsbService in your Program.cs or Startup.cs:

builder.Services.AddPsbService(options =>
{
    options.Username = "your-username";           // for Resource Owner flow
    options.Password = "your-password";           // for Resource Owner flow
    options.PsbUrl = "https://accp-psb.econnect.eu";
    options.IdentityUrl = "https://accp-identity.econnect.eu";
    options.ClientId = "your-client-id";
    options.ClientSecret = "your-client-secret";
    options.SubscriptionKey = "your-subscription-key"; // optional, legacy
});
EnvironmentPsbUrlIdentityUrlAcceptancehttps://accp-psb.econnect.euhttps://accp-identity.econnect.euProductionhttps://psb.econnect.euhttps://identity.econnect.eu

Which OAuth2 flow you use determines which fields you fill in. See Authentication for Client Credentials versus Resource Owner Password Credentials.

Available API interfaces

After registration you can inject the following interfaces:

InterfaceUseIPsbMeApiAccount and tenant detailsIPsbSalesInvoiceApiSend sales invoicesIPsbPurchaseInvoiceApiRetrieve purchase invoicesIPsbSalesOrderApi / IPsbPurchaseOrderApiOrdersIPsbHookApiManage webhooksIPsbPeppolApiPeppol registration and lookupIPsbGenericApiOther endpoints

Example in a controller:

public class InvoiceController
{
    private readonly IPsbSalesInvoiceApi _salesInvoice;

    public InvoiceController(IPsbSalesInvoiceApi salesInvoice)
    {
        _salesInvoice = salesInvoice;
    }
}

All interfaces are public and therefore mockable in unit tests.

Send your first invoice

The repository includes a working example in EConnect.Psb.Web.Example:

The pattern follows the SalesInvoice endpoint: upload an XML document; the PSB validates and routes automatically.

PsbServiceHost (without a DI framework)

If dependency injection is not available, use PsbServiceHost:

using var psb = PsbServiceHost.Create(options =>
{
    options.Username = "your-username";
    options.Password = "your-password";
    options.PsbUrl = "https://accp-psb.econnect.eu";
    options.IdentityUrl = "https://accp-identity.econnect.eu";
    options.ClientId = "your-client-id";
    options.ClientSecret = "your-client-secret";
    options.SubscriptionKey = "your-subscription-key";
});

var result = await psb.SalesInvoice
    .QueryRecipientParty("{senderPartyId}", new[] { "{receiverPartyId}" })
    .ConfigureAwait(false);

Console.WriteLine(result);

A console example is available in EConnect.Psb.ConsoleNet.Example.

Validate webhooks

PSB webhooks are secured with the X-EConnect-Signature header. The EConnect.Psb.AspNetCore.Mvc package validates that signature via an attribute on your controller method.

Hardcoded secret:

[PsbWebhook("mySecret")]
public IActionResult Webhook([PsbWebhookValidSentOn] PsbWebHookEvent @event)
{
    // process webhook event
    return Ok();
}

Secret from configuration:

[PsbWebhookOptions("webhook")]
public IActionResult Webhook([PsbWebhookValidSentOn] PsbWebHookEvent @event)
{
    return Ok();
}

More about webhook configuration: Configure webhooks.

Error handling

The SDK throws exceptions on HTTP errors. In production, implement:

  • 401 — token expired; the service usually re-authenticates automatically on the next call
  • 400 — validation error; log the response body and correct the source document
  • 409 — idempotency conflict; document already processed
  • 5xx — retry with exponential backoff; the PSB also retries on delivery failures
Frequently asked questions
Can I use NSwag instead of EConnect.Psb?

Yes. NSwag can generate client code from the swagger.json on psb.econnect.eu. EConnect.Psb additionally provides ready-made DI registration, token management and webhook validation. See also OpenAPI codegen.

Which .NET versions are supported?

The package targets .NET Standard 2.0. That covers .NET Core 2.0+, .NET 5+ and .NET Framework 4.6.1+. Check the NuGet page for current version information.