using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; var clientId = Required("DECISIOQ_CLIENT_ID"); var clientSecret = Required("DECISIOQ_CLIENT_SECRET"); var audience = Environment.GetEnvironmentVariable("DECISIOQ_AUDIENCE") ?? "vinquery:api:decisioq"; var identityUrl = Environment.GetEnvironmentVariable("DECISIOQ_IDENTITY_URL") ?? "https://identity.vinquery.com/connect/token"; var dksUrl = Environment.GetEnvironmentVariable("DECISIOQ_DKS_URL") ?? "https://dks.vinquery.com"; var ddeUrl = Environment.GetEnvironmentVariable("DECISIOQ_DDE_URL") ?? "https://dde.vinquery.com"; var correlationId = $"auto-part-039-csharp-{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}"; using var http = new HttpClient(); var tokenResponse = await http.PostAsJsonAsync(identityUrl, new { clientId, clientSecret, audience }); tokenResponse.EnsureSuccessStatusCode(); using var tokenJson = await JsonDocument.ParseAsync(await tokenResponse.Content.ReadAsStreamAsync()); var token = tokenJson.RootElement.GetProperty("jwtToken").GetString(); http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); http.DefaultRequestHeaders.Add("X-Correlation-Id", correlationId); var detail = await http.GetAsync($"{dksUrl.TrimEnd('/')}/decisioncatalog/decisions/AUTO-PART-039"); detail.EnsureSuccessStatusCode(); var requestJson = await File.ReadAllTextAsync("auto-part-039-execute.json"); using var request = new StringContent(requestJson, System.Text.Encoding.UTF8, "application/json"); var decision = await http.PostAsync($"{ddeUrl.TrimEnd('/')}/api/v1/execute-catalog", request); var body = await decision.Content.ReadAsStringAsync(); Console.WriteLine(body); decision.EnsureSuccessStatusCode(); static string Required(string name) => Environment.GetEnvironmentVariable(name) ?? throw new InvalidOperationException($"Missing required environment variable {name}.");