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.
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
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
});
PsbUrlIdentityUrlhttps://accp-psb.econnect.euhttps://accp-identity.econnect.euhttps://psb.econnect.euhttps://identity.econnect.euWhich OAuth2 flow you use determines which fields you fill in. See Authentication for Client Credentials versus Resource Owner Password Credentials.
After registration you can inject the following interfaces:
IPsbMeApiIPsbSalesInvoiceApiIPsbPurchaseInvoiceApiIPsbSalesOrderApi / IPsbPurchaseOrderApiIPsbHookApiIPsbPeppolApiIPsbGenericApiExample 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.
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.
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.
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.
The SDK throws exceptions on HTTP errors. In production, implement:
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.
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.