How can we pass string[] values to lambda call using .net core

Viewed 74

Here in the below externalRateCardIds is a string[]. I need to pass the string[] to invoke lambda but when trying to call the endpoint, it tells that no input has been sent. How can we pass string[] to lambda call using JObject?

JArray array = new JArray();
array.Add(externalRateCardIds);

JObject queryParam = new JObject();
queryParam.Add("externalRateCardIds", array);

var externalRateCardLambdaResponse = 
await _lambdaInvoker.InvokeLambdaWithResponseAsync(
    EnvironmentVariables.ApiLambdaLongName,
    $"/api/Bill/GetBillByExternalID",
    "get", 
    new JObject(), 
    queryParam);
1 Answers

JArray.Add adds an item to the array, not a range of items (similar to the difference between List<T>.Add and List<T>.AddRange). If you intend to populate your JArray with the values from your string array (one token per string), a simple loop would suffice.

JArray array = new JArray();
foreach (var id in externalRateCardIds)
    array.Add(id);
//...
Related