// Set request headers, base URL
IHttpClientFactory cf = new HttpClientFactory();
HttpClient client = cf.CreateClient();
client.BaseAddress = new Uri("http://localhost/ExagoWebApi");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue('ExagoKey APIUSER:EncodedAuthorizationString');
// STEP 1: Instantiate Api Object, POST to sessions endpoint
content = new StringContent(JsonConvert.SerializeObject(new { }));
res = await client.PostAsync("/rest/sessions", content);
string body = await res.Content.ReadAsStringAsync();
Dictionary<string, object> dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(body);
string sessionId = dict["Id"].ToString(); // grab Exago's session id from response
// STEP 2: Set userId parameter
content = new StringContent(JsonConvert.SerializeObject(new { Value = id }));
res = await client.PatchAsync("/rest/parameters/userId?sid=" + sessionId, content);
// STEP 3: Set identity values for Storage Management
StorageMgmtObj storageMgmtObj = new StorageMgmtObj();
storageMgmtObj.Identities = new IdentityObj
{userId=[userId], companyId=[companyId], classId=[classId], ownerId=[ownerId]};
content = new StringContent(JsonConvert.SerializeObject(storageMgmtObj));
res = await client.PatchAsync("/rest/StorageMgmt?sid=" + sessionId, content);
// STEP 4: Activate a Role
content = new StringContent(JsonConvert.SerializeObject(new { IsActive = true }));
res = await client.PatchAsync("/rest/roles/Admin?sid=" + sessionId, content);
// Exago session setup complete; return ApiKey
return JsonConvert.SerializeObject(new { ApiKey = dict["ApiKey"].ToString() });