https://www.growthbook.io/ logo
s

steep-queen-6488

09/23/2022, 7:34 AM
Hi all - Just trying to get to grips with the newish C# SDK - I'm struggling to populate the features dictionary in Context with the API response JSON. Does anyone have a code snippet that could help, there doesn't appear to be any documentation ?
f

fresh-football-47124

09/23/2022, 7:40 AM
@proud-family-69484 might be able to help you
s

steep-queen-6488

09/23/2022, 8:18 AM
I worked it out... var httpClient = new HttpClient(); var response = await httpClient.GetAsync("https://cdn.growthbook.io/api/features/MY_KEY"); if (response.IsSuccessStatusCode) { var featuresResp = JObject.Parse(await response.Content.ReadAsStringAsync()); var features = featuresResp["features"]; // Create and populate the context object var context = new GrowthBook.Context(); context.Features = features.Cast<JProperty>() .ToDictionary(item => item.Name, item => item.Value.ToObject<Feature>()); }
2 Views