0

I have an error while using

'query':'last_event_time=2022-02-14T08:52:44Z'

it gives me unexpected identifier 'query' error, here is my code

var response = await client.SendEmailAsync(myMessage);  
var data = response.Headers.ToString();  
var splitData = data.Split("\r\n")[1].TrimStart('D', 'a', 't', 'e', ':').Replace("GMT", " ").Trim();  
var dateFormat = "ddd, dd MMM yyyy HH:mm:ss";  
DateTime emailSentDate;
bool date1 = DateTime.TryParseExact(splitData, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out emailSentDate);      
var lastEmailSent = emailSentDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssZ");  
var queryParams = @"{
      'query':'last_event_time"+lastEmailSent+"'"+","+"from_email:'"+From_Email+"'"+","+"subject:'"+myMessage.Subject+"'"+","+"limit:1"+"}";  

still this error was encounterd. I dont get exactly how to use 'query':'last_event_time="+lastEmailSent

D M
  • 39
  • 6

1 Answers1

0

Twilio SendGrid developer evangelist here.

In your code you have 'query':'last_event_time"+lastEmailSent. I think you are missing an = in there. Each query item should also have quotes around it, like you have for the others, like from_email. You already had the quote after the lastEmailSent, but were missing =' before it. Try the string below.

var queryParams = @"{
    'query':'last_event_time='"+lastEmailSent+"'"+","+"from_email:'"+From_Email+"'"+","+"subject:'"+myMessage.Subject+"'"+","+"limit:1"+"}";  

philnash
  • 70,667
  • 10
  • 60
  • 88
  • yes, I had tried your solution but it gives me error for 'query' key in the queryparams json object string like this 'Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: l. Path 'query', line 2, position 24.' When i was checked the position 24 it takes me to the 'query' . I need more clarification for this exactly how to use 'query' in json object string – D M Feb 16 '22 at 05:54
  • Sorry, I didn't get back to this, but I see you just marked it as solved. Did you figure out what went wrong? Should I edit my answer to reflect what actually worked? – philnash Feb 23 '22 at 23:01
  • yes now this 'query' problem in queryParams was solved now but in different way, I was tried BETWEEN TIMESTAMP with last_event_time to solve this problem like below. Thanks. var queryParams = "(last_event_time BETWEEN TIMESTAMP " + "'" + lastEmailSent + "'" + " AND TIMESTAMP " + "'" + date2 + "'" + ") AND from_email='" + From_Email + "' AND subject='" + myMessage.Subject + "'"; – D M Feb 24 '22 at 05:47