Skip to main content


This is an example of using the platform via REST. For more sample code, including any dependencies this file has, please have a look at our GitHub examples repository. This file can be found in that repo at csharp/rest/RestQueryData.cs

using System.Text.Json;

class RestQueryData
/// <summary>
/// Queries a Vectara corpus.
/// </summary>
/// <param name="customerId"> The unique customer ID in Vectara platform. </param>
/// <param name="corpusId"> The corpus that needs to be queried. </param>
/// <param name="query"> The query text. </param>
/// <param name="servingEndpoint"> Serving API endpoint to which calls will be directed. </param>
/// <param name="jwtToken"> A valid authentication token. </param>
public static void Query(long customerId, long corpusId, String query, String servingEndpoint, String jwtToken)
using (var client = new HttpClient())
var request = new HttpRequestMessage
RequestUri = new Uri($"https://{servingEndpoint}/v1/query"),
Method = HttpMethod.Post,
Dictionary<String, Object> queryData = new();
List<Object> queryList = new();
List<Object> corpusList = new();
corpusList.Add(new Dictionary<String, Object>()
{"customerId", customerId},
{"corpusId", corpusId}
queryList.Add(new Dictionary<String, Object>()
{"query", query},
{"numResults", 10},
{"corpusKey", corpusList}

queryData.Add("query", queryList);

string jsonData = JsonSerializer.Serialize(queryData);

request.Content = new StringContent(jsonData);
request.Content.Headers.Add("Content-Type", "application/json");

request.Headers.Add("Authorization", $"Bearer {jwtToken}");
request.Headers.Add("customer-id", customerId.ToString());

HttpResponseMessage response = client.Send(request);
String result = response.Content.ReadAsStringAsync().Result;

catch (Exception ex)