Haseeb Ahmad
Haseeb Ahmad

Reputation: 8730

Twilio - The requested resource not found error. when sending sms messages

When I send any message it gives an error.

Twilio::REST::RequestError: The requested resource /2010-04-01/Accounts/cafac01e41ad5fbad3da4ad8619c8d36/Messages.json was not found

# set up a client to talk to the Twilio REST API 
    @client = Twilio::REST::Client.new account_sid, auth_token 
    @client.account.messages.create({
      :from => 'xxxxxx', 
      :to => 'xxxxxx', 
      :body => 'Twilio Testing',  
    })

Upvotes: 1

Views: 2263

Answers (1)

Megan Speir
Megan Speir

Reputation: 3811

Aside from the potential issue Devin brought up in the comments regarding an incorrect Account SID in your Url, the following code examples may help.

Code to setup Twilio-Ruby:

require 'rubygems' # not necessary with ruby 1.9 but included for completeness
require 'twilio-ruby'

# put your own credentials here
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'

# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token

# alternatively, you can preconfigure the client like so
Twilio.configure do |config|
  config.account_sid = account_sid
  config.auth_token = auth_token
end

# and then you can create a new client without parameters
@client = Twilio::REST::Client.new

And then the code to send an SMS:

@client.messages.create(
  from: '+1415XXXXXXX',
  to: '+1610XXXXXXX',
  body: 'Hey there!'
)

Upvotes: 1

Related Questions