C# Uniconta Code

Date: 2021-01-27
public class UnicontaConnectionHelper 
{
    public static async Task<CrudAPI> GetApi (string username, string password, Guid apiKey, int companyId) {
        var connection = new UnicontaConnection (APITarget.Live);
        var session = new Session (connection);
        var result = await session.LoginAsync (username, password, LoginType.API, apiKey);
        if (result != ErrorCodes.Succes) {
            throw new Exception (result.ToString ());
        }
        var company = await session.GetCompany (companyId);
        var crudApi = new CrudAPI (session, company);
        crudApi.ForcePrimarySQL = true;
        return crudApi;
    }
    
    public async Task<CrudAPI> GetCrudAPI () {
        string username = "user";
        string password = "pwd";
        int companyId = 48745;
        Guid apiKey = Guid.Parse ("21245d5e-22f8-4468-a198-e6b0eb5eff92");
        return await UnicontaConnectionHelper.GetApi (username, password, apiKey, companyId);
    }
}
44960cookie-checkC# Uniconta Code