0
 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.

D M
  • 39
  • 6

1 Answers1

0

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.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • yes, I have tried this even though I get empty result. I just find out msg_id start with specific value using LIKE operator but expected results are empty. I don't understand how to use this LIKE operator for msg_id. – D M Apr 12 '22 at 05:34
  • I used [https://docs.sendgrid.com/for-developers/sending-email/getting-started-email-activity-api#keywords-and-operator-reference] this for reference. – D M Apr 12 '22 at 06:24
  • 1
    If you have the specific message ID, can you use `=` instead of `LIKE`? – philnash Apr 12 '22 at 06:25
  • yes, but I have the value which is at the starting position in message ID. **For Ex.** I have value **'XBg2anf2TqCy6WXKQFhieQ'** which is starting position in message ID **'XBg2anf2TqCy6WXKQFhieQ.filter0905p1mdw1-4434-59E0C6FF-3.0'**. And I want to find out `msg_id` start with `'XBg2anf2TqCy6WXKQFhieQ'` this value. – D M Apr 12 '22 at 06:31