I've reviewed every post I can find about resource not found on twilio. There is nothing wrong with my credentials. In fact, I use the api to retrieve the messages, then I get a not found error when trying to update the messages that the api just told me exist. I've spent hours on this and it's driving me nuts. Below is my code. The read function returns the sid, which I can look up in my twilio console, but then I'm told it doesn't exist when trying to update the message using that very same sid. The console gets a readout of the first message sid, then the error is thrown with the following: Twilio.Exceptions.ApiException: 'The requested resource /2010-04-01/Accounts//Messages/SMc7943a93549acef10f1e49876a8652b6.json was not found'
static readonly string accountSid = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
static readonly string authToken = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
static void Main(string[] args)
{
TwilioClient.Init(accountSid, authToken);
var messages = MessageResource.Read(
dateSent: new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 0, 0, 0)
);
foreach(var message in messages)
{
Console.WriteLine(message.Sid);
MessageResource.Update(pathSid: message.Sid, "");
}
}
The error message shows the AccountSid is missing from the path as there is a double slash:
Twilio.Exceptions.ApiException: 'The requested resource /2010-04-01/Accounts//Messages/SMc7943a93549acef10f1e49876a8652b6.json was not found'
The path should be something like:
/2010-04-01/Accounts/{{ACCOUNTSID}}/Messages/SMc7943a93549acef10f1e49876a8652b6.json
The update you are trying to doesn't appear to be valid unless you are trying to redact the message:
MessageResource.Update(pathSid: message.Sid, "");
If you are trying to redact the message body:
MessageResource.Update(pathSid: message.Sid, body: "");
If you are trying to delete:
MessageResource.Delete(pathSid: "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
If the delete/update still aren't working, try casting the ResourceSet of MessageResource to a list:
static readonly string accountSid = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
static readonly string authToken = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
static void Main(string[] args)
{
TwilioClient.Init(accountSid, authToken);
var messages = MessageResource.Read(
dateSent: new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 0, 0, 0)
);
var messageList = messages.ToList();
foreach(var message in messageList)
{
Console.WriteLine(message.Sid);
MessageResource.Delete(pathSid: message.Sid);
}
}