简体   繁体   中英

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);

Here I want to find out msg_id start with this value 'pBRuJA0OSqyRAHaT2sW8hg' and I code for this as above. I used LIKE operator here but it gives me empty response. How to use LIKE operator if we want to find out startwith or endwith values? Does anyone know how this could be done? Thanks for your help & time.

This might be an empty result because you are not url encoding the request. It looks like you are using RestSharp to make requests to the API here, so what you can try instead is:

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);

This way you create an object of the parameters you want to pass and let the request object handle encoding them .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM