Joshua Soileau
Joshua Soileau

Reputation: 3015

Laravel API controller returns 404 when hit through Twilio

I am trying to set up a route that I can let Twilio hit, that will return a response from Laravel.

But every Twilio request kicks back a 404 Http Response.

Feels like I've got something misconfigured.

I have

  1. Created ControllerClass SmSController with a reply method.
  2. Added my route to routes/api.php to hit the controller.
  3. Added my URL to the $except property in app/Http/Middleware/VerifyCsrfToken.php

Here's my app/Http/Controllers/SmsController.php:

namespace App\Http\Controllers;

use Illuminate\Http\Request; use Twilio\Twiml;

class SmsController extends Controller { public function reply(Request $request) { $response = new Twiml; $response->message("Hello World!"); print $response; } }

And Here's my routes/api.php:

Route::group([
    'middleware' => 'auth:api'
], function () {
    //
});
Route::post('sms/reply', 'SmsController@reply');

And inside the class VerifyCsrfToken I have:

protected $except = [
    'sms/reply'
];

Edit: I should mention, I have Twilio to hit the URL: https://www.MYWEBSITE.com/sms/reply, which I think should correspond to the route I set up in api.pip

Upvotes: 1

Views: 152

Answers (1)

Nikola Gavric
Nikola Gavric

Reputation: 3543

All the routes inside of api.php are prefixed with api inside a url, so your sms/reply is actually api/sms/reply, does this make sense?

Upvotes: 2

Related Questions