diff --git a/FunctionApp/LoxoSettings.cs b/FunctionApp/LoxoSettings.cs index 6700106..a2aec95 100644 --- a/FunctionApp/LoxoSettings.cs +++ b/FunctionApp/LoxoSettings.cs @@ -1,7 +1,8 @@ -namespace LoxoIntegration; +using System.Collections.Generic; + +namespace LoxoIntegration; public class LoxoSettings { - public string AgencySlug { get; set; } - public string BearerToken { get; set; } + public Dictionary Tokens { get; set; } } \ No newline at end of file diff --git a/FunctionApp/UploadDocumentToLoxo.cs b/FunctionApp/UploadDocumentToLoxo.cs index 9bb2dd0..6021726 100644 --- a/FunctionApp/UploadDocumentToLoxo.cs +++ b/FunctionApp/UploadDocumentToLoxo.cs @@ -30,6 +30,7 @@ public async Task Run( dynamic data = JsonConvert.DeserializeObject(requestBody); string fileUrl = data?.fileUrl; string personId = data?.data?.personID; + string slug = data?.data?.slug; if (string.IsNullOrEmpty(fileUrl)) { @@ -41,6 +42,11 @@ public async Task Run( return new BadRequestObjectResult("Missing personID in request body."); } + if (string.IsNullOrEmpty(slug)) + { + return new BadRequestObjectResult("Missing slug in request body."); + } + using var httpClient = new HttpClient(); var response = await httpClient.GetAsync(fileUrl); @@ -55,7 +61,7 @@ public async Task Run( httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Authorization = - new AuthenticationHeaderValue("Bearer", _settings.BearerToken); + new AuthenticationHeaderValue("Bearer", _settings.Tokens[slug]); using (var content = new MultipartFormDataContent()) { @@ -65,7 +71,7 @@ public async Task Run( content.Add(fileContent, "document", fileName); var postResponse = await httpClient.PostAsync( - $"https://app.loxo.co/api/{_settings.AgencySlug}/people/{personId}/documents", content); + $"https://app.loxo.co/api/{slug}/people/{personId}/documents", content); if (!postResponse.IsSuccessStatusCode) {