如何在查询 sendgrid 电子邮件 activity 时对 msg_id 或 from_email 或 to_email 使用 LIKE 运算符?

How to use LIKE operator for msg_id or from_email or to_email in query for sendgrid email activity?

 var queryParams = "msg_id LIKE'pBRuJA0OSqyRAHaT2sW8hg'";
var client = new RestClient("https://api.sendgrid.com/v3/messages?query=" + queryParams + "&limit=1");
var request = new RestRequest(Method.GET);
client.Timeout = -1;
request.AddHeader("x-query-id", "{{x-query-id}}");
request.AddHeader("x-cursor", "{{x-cursor}}");
request.AddHeader("authorization", "bearer " + ApiKey);
IRestResponse response = client.Execute(request);
var sendGridEmailDetails = JsonConvert.DeserializeObject<SendGridResponse>(response.Content);

这里我想找出 msg_id 从这个值 'pBRuJA0OSqyRAHaT2sW8hg' 开始,我为此编写了上面的代码。我在这里使用了 LIKE 运算符,但它给了我空洞的回应。如果我们想找出 startwithendwith 值,如何使用 LIKE 运算符?有谁知道如何做到这一点?感谢您的帮助和时间。

这可能是一个空结果,因为您没有 url 对请求进行编码。看起来您正在使用 RestSharp 向此处的 API 发出请求,因此您可以尝试改为:

var params = new {
  query = "msg_id LIKE 'pBRuJA0OSqyRAHaT2sW8hg'",
  limit = 1
}
var client = new RestClient("https://api.sendgrid.com/v3/messages");
var request = new RestRequest(Method.GET);
request.addObject(params);

client.Timeout = -1;
request.AddHeader("x-query-id", "{{x-query-id}}");
request.AddHeader("x-cursor", "{{x-cursor}}");
request.AddHeader("authorization", "bearer " + ApiKey);
IRestResponse response = client.Execute(request);
var sendGridEmailDetails = JsonConvert.DeserializeObject<SendGridResponse>(response.Content);

通过这种方式,您可以创建一个包含要传递的参数的对象,let the request object handle encoding them