2

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

Doug Steinberg
  • 1,122
  • 14
  • 32

1 Answers1

2

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.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thanks. You're right. I didn't realize that there are notifications and messages. I need to read the twilio docs more carefully. What is the difference between a notification and message? – Doug Steinberg Nov 14 '14 at 20:01
  • No worries Doug. Messages refer to SMS messages that are sent or received by your account. Notifications are actually logs of any thing that happens within your account. You can see more detail on them in the docs: https://www.twilio.com/docs/api/rest/notification – philnash Nov 15 '14 at 17:41