Use the official Mux SDK for C# to call the Mux API from your server. The SDK handles authentication and wraps each API endpoint in native C# code.
The Mux SDK for C# wraps the Mux REST API in native C# code. Use this SDK when you write your server application in C# or another .NET language. You can create assets, manage live streams, and query Mux Data without manual HTTP requests.
The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:
Install-Package RestSharp
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.ComponentModel.AnnotationsNOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See RestSharp#742
Generate the DLL using your preferred tool (e.g. dotnet build)
Then include the DLL (under the bin folder) in the C# project, and use the namespaces:
using Mux.Csharp.Sdk.Api;
using Mux.Csharp.Sdk.Client;
using Mux.Csharp.Sdk.Model;Usage With Webhooks
At this moment, this SDK is not suitable for parsing or modeling webhook payloads, due to some incompatibilities in our API spec and our SDK generation tooling. We are working on resolving these issues, but for now you should only use this SDK for Mux's REST APIs.
To use the API client with a HTTP proxy, setup a System.Net.WebProxy
Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;using System.Collections.Generic;
using System.Diagnostics;
using Mux.Csharp.Sdk.Api;
using Mux.Csharp.Sdk.Client;
using Mux.Csharp.Sdk.Model;
namespace Example
{
public class Example
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "https://api.mux.com";
// Configure HTTP basic authorization: accessToken
config.Username = "YOUR_USERNAME";
config.Password = "YOUR_PASSWORD";
var apiInstance = new AssetsApi(config);
var createAssetRequest = new CreateAssetRequest(); // CreateAssetRequest |
try
{
// Create an asset
AssetResponse result = apiInstance.CreateAsset(createAssetRequest);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling AssetsApi.CreateAsset: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}Check out the Mux C# SDK docs for more information.