Hi Friends,
I got a requirement where I have to retrieve all the messages I sent using Twilio number in one day. This was like any other simple requirement and can be easily achieved through exporting the records in .CSV format as given in Twilio Dashboard. The twist is that Twilio dashboard supports only to fetch 10000 records(however in my case it was not exporting more than 5000 records out of some odd 8000 records and putting error message "Could not finish exporting all records." in the exported .CSV file).
This is the story about when you have to fetch within 10000 records. In case you want to fetch records more than that then following is the code for your rescue which I figured out after hit and trial as Twilio support was also much not helpful:
This is how I got it working:
For Collecting Responses to Twilio Numbers
TwilioRestClient client = new TwilioRestClient(accountSID, authToken);
for (int count = 0; count <= 3; count++)
{
var smss = client.ListSmsMessages("Your number to which you received messages", null, null, count, 1000);
foreach (var sms in smss.SMSMessages)
{
//Saving in DB
SaveToDB(sms.Sid, sms.From, sms.To, sms.DateSent, sms.Body);
}
}
For Collecting Sent Message From Twilio Numbers
TwilioRestClient client = new TwilioRestClient(accountSID, authToken);
for (int count = 0; count <= 3; count++)
{
var smss = client.ListSmsMessages(null, "Your number through which you sent messages", null, count, 1000);
foreach (var sms in smss.SMSMessages)
{
//Saving in DB
SaveToDB(sms.Sid, sms.From, sms.To, sms.DateSent, sms.Body);
}
}
*count is the number of pages you are expecting which can be calculated by dividing the no. of messages by 1000(max records supported by API in one request)
I got a requirement where I have to retrieve all the messages I sent using Twilio number in one day. This was like any other simple requirement and can be easily achieved through exporting the records in .CSV format as given in Twilio Dashboard. The twist is that Twilio dashboard supports only to fetch 10000 records(however in my case it was not exporting more than 5000 records out of some odd 8000 records and putting error message "Could not finish exporting all records." in the exported .CSV file).
This is the story about when you have to fetch within 10000 records. In case you want to fetch records more than that then following is the code for your rescue which I figured out after hit and trial as Twilio support was also much not helpful:
This is how I got it working:
For Collecting Responses to Twilio Numbers
TwilioRestClient client = new TwilioRestClient(accountSID, authToken);
for (int count = 0; count <= 3; count++)
{
var smss = client.ListSmsMessages("Your number to which you received messages", null, null, count, 1000);
foreach (var sms in smss.SMSMessages)
{
//Saving in DB
SaveToDB(sms.Sid, sms.From, sms.To, sms.DateSent, sms.Body);
}
}
For Collecting Sent Message From Twilio Numbers
TwilioRestClient client = new TwilioRestClient(accountSID, authToken);
for (int count = 0; count <= 3; count++)
{
var smss = client.ListSmsMessages(null, "Your number through which you sent messages", null, count, 1000);
foreach (var sms in smss.SMSMessages)
{
//Saving in DB
SaveToDB(sms.Sid, sms.From, sms.To, sms.DateSent, sms.Body);
}
}
*count is the number of pages you are expecting which can be calculated by dividing the no. of messages by 1000(max records supported by API in one request)