Skip to content

Commit

Permalink
adjust function to work with multiple agencies
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyziggy committed Apr 15, 2024
1 parent a7b6c1c commit 1d1128f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions FunctionApp/LoxoSettings.cs
Original file line number Diff line number Diff line change
@@ -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<string, string> Tokens { get; set; }
}
10 changes: 8 additions & 2 deletions FunctionApp/UploadDocumentToLoxo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public async Task<IActionResult> Run(
dynamic data = JsonConvert.DeserializeObject(requestBody);
string fileUrl = data?.fileUrl;
string personId = data?.data?.personID;
string slug = data?.data?.slug;

if (string.IsNullOrEmpty(fileUrl))
{
Expand All @@ -41,6 +42,11 @@ public async Task<IActionResult> 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);
Expand All @@ -55,7 +61,7 @@ public async Task<IActionResult> 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())
{
Expand All @@ -65,7 +71,7 @@ public async Task<IActionResult> 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)
{
Expand Down

0 comments on commit 1d1128f

Please sign in to comment.