Twilio error, resource not found when looking up SMS by SID

1.8k Views Asked by At

I'm trying to integrate twilio into my rails app. I want to be able to tell if there are any error messages using a response returned from the 'get' method

Twilio's example has this

@notification = @client.account.notifications.get("NO5a7a84730f529f0a76b3e30c01315d1a")

that was on this page https://www.twilio.com/docs/api/rest/notification

Here is how I'm calling it in rails console

client = Twilio::REST::Client.new(ENV['twilio_account_sid'], ENV['twilio_auth_token'])
n = client.account.notifications.get("SMb6e3a5d4649e485ea9fa818ba84ec721")
n.message_text

And I get this error

Twilio::REST::RequestError: The requested resource /2010-04-01/Accounts/[my account]/Notifications/SMb6e3a5d4649e485ea9fa818ba84ec721.json was not found

That sid is a valid sid, and I confirmed it by looking in my logs.

So why can't I look up the message with this method?

Thanks

1

There are 1 best solutions below

2
On BEST ANSWER

Twilio developer evangelist here.

I think the problem is that you are not looking up a notification in your example. The SID you are using is "SMb6e3a5d4649e485ea9fa818ba84ec721" which is for an SMS message (indicated by the "SM" at the front).

As you can see in the example from the docs, notification SIDs start with "NO".

You should be able to get hold of the message you are after using client.account.messages.get('SMb6e3a5d4649e485ea9fa818ba84ec721').

You can also find all the notifications to your account by calling client.account.notifications.list.

Hope this helps, let me know if you have any other questions.