Skip to content

Getting Started with USSD Admin API SDK

This SDK helps you to interact with USSD Admin API API. Helpful methods include:

  • Creating USSD code and attaching an item/service
  • Listing all USSD codes with filters
  • Topping up and getting session balance of legacy USSD codes

In order to get started, do the following activities:

Install-Package Hubtel.UssdAdmin.Sdk

The code snippet below is a command that's used in the NuGet Package Manager Console in Visual Studio. This command is written in PowerShell and it's used to install the Hubtel.UssdAdmin.Sdk package. into the current .NET project.

    Install-Package Hubtel.UssdAdmin.Sdk

Add to IServiceCollection in Program.cs or Startup.cs

  • services.AddHubtelUssdAdminSdk(o => { o.BaseUrl = "http://localhost:9067/"; }) is a method call to AddHubtelUssdAdminSdk on the services object. The services object is of type IServiceCollection, which is a framework-provided interface that is used to register services to the application's dependency injection container during the startup configuration phase.

  • The AddHubtelUssdAdminSdk method is an extension method that registers the Hubtel USSD Admin SDK services into the application's dependency injection container. This allows the SDK's services to be injected into other parts of the application where they are needed.

  • The method takes a lambda expression o => { o.BaseUrl = "http://localhost:9067/"; } as an argument. This lambda expression is used to configure the options for the Hubtel USSD Admin SDK. In this case, it sets the BaseUrl property of the options to "http://localhost:9067/". This URL is the base URL that the SDK will use when making HTTP requests to the USSD Admin service.

c#
     services.AddHubtelUssdAdminSdk(o => { o.BaseUrl = "http://localhost:9067/"; });

Inject and consume service methods

  • The code snippet below is be part of a C# class in a .NET application that interacts with a USSD (Unstructured Supplementary Service Data) service provided by Hubtel.

  • The first two lines declare two private readonly fields: _sessionsApi and _ussdCodesApi. These fields are of types IUssdSessionsApi and IUssdCodesApi respectively, which are interfaces defining the operations that can be performed on USSD sessions and codes. The comment suggests that these fields should be initialized via the constructor, which is a common practice in .NET for dependency injection.

  • The _sessionsApi field is used to manage USSD sessions. In the context of a USSD service, a session represents a conversation between a user and the USSD application.

  • The _ussdCodesApi field is used to manage USSD codes. USSD codes are the codes that users dial to interact with the USSD service.

  • The line var balance = await ussdSessionsApi.GetBalance("CalBank") is calling the GetBalance method on ussdSessionsApi, passing in "CalBank" as an argument. This method retrieves the balance for a specific bank (in this case, CalBank). The await keyword is used to asynchronously wait for the method to complete.

  • The line var codes = await ussdCodesApi.ListCodes(new FilterModel()) is calling the ListCodes method on ussdCodesApi, passing in a new instance of FilterModel as an argument. This method retrieves a list of USSD codes, possibly filtered based on the properties of the FilterModel. Again, the await keyword is used to asynchronously wait for the method to complete.

c#
    private readonly IUssdSessionsApi _sessionsApi; //use this to manage sessions    
    private readonly IUssdCodesApi _ussdCodesApi; //use this to manage codes
 
    //P.S. be sure to include as constructor parameter

    var balance = await ussdSessionsApi.GetBalance("CalBank");
    var codes = await ussdCodesApi.ListCodes(new FilterModel());