Azure ProgrammableConnectivity client library for .NET - version 1.0.0-beta.1

This client library allows .NET applications to interact with Azure Programmable Connectivity Gateway, instead of using curl requests. For information on APC, see docs.

Source code | Package (NuGet): https://www.nuget.org/packages/Azure.Communication.ProgrammableConnectivity | API reference documentation | Product documentation

Getting started

Install the package

Install the client library for .NET with NuGet:

dotnet add package Azure.Communication.ProgrammableConnectivity --prerelease

Prerequisites

Before you can use the SDK successfully, you'll need to

  • Follow the guide to create a gateway, or have one already.
  • Note down your endpoint and apc-gateway-id, which is retrieved by following the guide linked.

Authenticate the client

The client library uses Azure.Identity credentials to authenticate with APC. The examples given in this repo use DefaultAzureCredential.

Examples

You can familiarize yourself with different APIs using Samples.

Key concepts

For each call that you make to APC with the SDK, you will follow the same pattern:

  • Create a client and sub-client for your use case (sim-swap/location/number-verification/device-network)
  • Create the content for your request by using the objects given by the SDK
  • Call the client with the content
  • Access the result returned
string apcGatewayId = "/subscriptions/abcdefgh/resourceGroups/.../Microsoft.programmableconnectivity/...";
Uri endpoint = new Uri("https://your-endpoint-here.com");
TokenCredential credential = new DefaultAzureCredential();
ProgrammableConnectivityClient baseClient = new ProgrammableConnectivityClient(endpoint, credential);
SimSwap client = baseClient.GetSimSwapClient();

SimSwapRetrievalContent content = new SimSwapRetrievalContent(
    new NetworkIdentifier("NetworkCode", "Orange_Spain"))
{
    PhoneNumber = "+50000000000",
};

Response<SimSwapRetrievalResult> response = await client.RetrieveAsync(apcGatewayId, content);
Console.WriteLine(response.Value.Date);

When handling an error, catch RequestFailedException, and log the details.

string apcGatewayId = "/subscriptions/abcdefgh/resourceGroups/.../Microsoft.programmableconnectivity/...";
Uri endpoint = new Uri("https://your-endpoint-here.com");
TokenCredential credential = new DefaultAzureCredential();
ProgrammableConnectivityClient baseClient = new ProgrammableConnectivityClient(endpoint, credential);
DeviceNetwork client = baseClient.GetDeviceNetworkClient();

NetworkIdentifier networkIdentifier = new NetworkIdentifier("IPv5", "127.0.0.1");
try
{
    Response<NetworkRetrievalResult> response = await client.RetrieveAsync(apcGatewayId, networkIdentifier);
}
catch (RequestFailedException ex)
{
    Console.WriteLine($"Exception Message: {ex.Message}");
    Console.WriteLine($"Status Code: {ex.Status}");
    Console.WriteLine($"Error Code: {ex.ErrorCode}");
}

Troubleshooting

If your call doesn't work, we recommend logging the exception messages, and progressing from there.

Try sending the request with curl or with HTTP files, using postman for example. This will narrow down the issue you're facing.

Next steps

For more information about Microsoft Azure SDK, see this website.

Contributing

APC is currently not accepting/expecting contributions for this codebase. Suggestions/issues are welcome.

Impressions