Skip to content

C#/.NET client library

To use this library you first need to install the Azure Artifacts Credential Provider. Then add a reference to the EnBW.EnPowerX.Apis NuGet package. You may need to run dotnet restore --interactive and log in once.

Add the following to your ConfigureServices() method:

services.AddEnPowerXClients(_configuration.GetSection("Apis"));

Set the API endpoint URL and Authentication credentials, e.g. via appsettings.json:

{
    "Apis": {
        "Uri": "https://apis.enpowerx.io/",
        "OAuth": {
            "Uri": "https://auth.enpowerx.io/",
            "ClientId": "abc123",
            "ClientSecret": "xyz456"
        }
    }
}

You can then use dependency injection to get a client. For example, to get a client for io.enpowerx.resources.v1.Offers:

public MyService(Resources.V1.Offers.OffersClient offersClient)
{
    _offersClient = offersClient;
}

To perform error handling catch RpcExceptions. You can use the .GetDetail<>() extension method to check for custom error types. For example:

try
{
    await _offersClient.SetStateAsync(new SetOfferStateRequest {Tenant = "esw", Id = id, State = Offer.Types.State.Accepted});
}
catch (RpcException ex) when (ex.GetDetail<NotFoundTenantError>() != null)
{
    _logger.LogError("Tenant not found");
}