C# client library to access Survey Solutions public api.
- create a new api user as described here.
- Install nuget package
- Then create a api client with following code sample:
Credentials creds = new Credentials("apiUser", "apiPassword");
string surveySolutionsUrl = "https://demo.mysruvey.solutions";
var surveySolutionsApiConfiguration = new SurveySolutionsApiConfiguration(creds, surveySolutionsUrl);
var client = new SurveySolutionsApi(new HttpClient(), surveySolutionsApiConfiguration);
var assignmentsList = await client.Assignments.ListAsync(new AssignmentsListFilter());
More usage examples can be found in tests folder
Please use https://www.nuget.org/packages/SurveySolutionsClient.DependencyInjection package to use C# client with Microsoft.Extensions.DependencyInjection library.
Sample configuration in Net 6.0 application
using SurveySolutionsClient;
var builder = WebApplication.CreateBuilder(args);
Credentials creds = new Credentials("apiUser", "apiPassword");
string surveySolutionsUrl = "https://demo.mysruvey.solutions";
builder.Services.ConfigureSurveySolutionsApiClient(creds, surveySolutionsUrl);
builder.Services.AddSurveySolutionsApiClient();
var app = builder.Build();
app.Run();
There is also support for Options pattern in ASP.NET Core
Let's assume, that You configration contains following section:
"SurveySolutions": {
"UserName": "apiUser",
"Password": "apiPassword",
"Url": "https://demo.mysruvey.solutions",
"Workspace": "agriculture"
}
Then in C# code
using SurveySolutionsClient;
var builder = WebApplication.CreateBuilder(args);
builder.ConfigureSurveySolutionsApiClient(builder.Configuration.GetSection("SurveySolutions"));
builder.Services.AddSurveySolutionsApiClient();
var app = builder.Build();
app.Run();