5

Sending twilio message from my api returns this error

Twilio sending message The requested resource /2010-04-01/Accounts//Messages.json was not found

this is how I send a message. anyone incountered a problem?

$this->client = new \Services_Twilio($sid, $token);
     return $this->client->account->messages->sendMessage($from ,$to, $message);

this is the documentation I followed

https://www.twilio.com/docs/api/rest/sending-sms

How do I create Messages.json

I used this https://github.com/twilio/twilio-php on laravel 4.2

Nean
  • 75
  • 1
  • 2
  • 8

3 Answers3

11

Another Twilio developer evangelist here. Think I might be able to help.

The error message you got was this:

The requested resource /2010-04-01/Accounts//Messages.json was not found

The key point is the URL, particularly the double slash in the middle. That is where your Account Sid should be, thus leading to the 404 error.

In this case, I would double check how you are setting $sid. Make sure it is assigned before you try to create the Twilio client object.

shareef
  • 9,255
  • 13
  • 58
  • 89
philnash
  • 70,667
  • 10
  • 60
  • 88
0

You have entered messages when it should be sms_messages.

CHANGE

$this->client->account->messages->sendMessage($from ,$to, $message);

INTO

$this->client->account->sms_messages->create($from ,$to, $message);

Also make sure that you are running this code inside a class otherwise you need to remove the $this-> from your code and use a local varible.

user2420647
  • 183
  • 11
  • Also make sure that you have autorized the recipient if on trial account. – user2420647 Oct 04 '15 at 14:10
  • I dunno if it's safe to share the sid and token but currently im using the twilio library the one that's located on github. also it's a paid account – Nean Oct 04 '15 at 15:01
  • I would like to know more about the class that you run this inside because of that you get no error messages. If you remove the keys and then post the class that you are using somewhere then that would help. Sounds to me if you do not get an error message that you are not running this inside a class but outside of it and it crashes beacuse of this fact. – user2420647 Oct 04 '15 at 15:51
  • `sms_messages` actually uses a deprecated API endpoint, using `messages` is correct. I feel there is something else going wrong here. – philnash Oct 05 '15 at 13:45
0

Hi Twilio developer evangelist here.

Sorry to hear you're having trouble with your code.

You seem to not have posted your complete code, so I don't see where you actually require the library.

I have however written an example which worked for me.

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = 'AC'; 
$token = '01'; 
$client = new \Services_Twilio($sid, $token);

$message = $client->account->messages->sendMessage(
    '+44', // From a valid Twilio number
    '+44', // Text this number
    "Hello monkey!"
);

I have removed some sensitive data on the code, but if you replace that with your token and numbers, you should be able to send a text message correctly.

Also, just in case you have the contents of the 'Services' folder elsewhere, make sure your paths are correct.

Marcos Placona
  • 21,468
  • 11
  • 68
  • 93
  • 1
    after days of this problem. I found out that im using a null variable of $sid and token. – Nean Oct 06 '15 at 05:31