How to Fix 419 Postman Error Laravel API Request

How to Fix 419 Postman Error Laravel API Request

I recently encountered a rather annoying error while trying to test my API endpoints with postman. At first, I assumed there was something wrong with my code since I hadn't built the front end and can't quite determine where the error is from.

So I began troubleshooting, I decided to run an API post request of a fully functional app that works and sure enough, the error popped up again. This eliminated the possibility that there could be something wrong with my code since this fully functional app gave me the same error in postman when I could carry out crud operations on the app after running 'php artisan serve'.

Carried out a little research, more like typing "419 postman error'' on google, lmao. and it had to do with CORS || XSRF tokens.

Anyway, the quickest way to fix this and get back to running those API tests is to open the 'VerifyCsrfToken.php' file you can type 'CTRL or CMD + P' and type it out on VSCODE. Or navigate to your app folder >>Http >>Middleware >> VerifyCsrfToken.php.

Then paste this '*' inside

protected $except = [
//

];

should look like this:

protected $except = [
//
    "*"
];

Save. Restart your server and your GET, POST, PUT, DELETE requests should work just fine on Postman.

PS: I believe this isn't a permanent or the most optimal way to fix this error, but it works. I also recommend that you delete the asterisks once you push your code to production.

I hope you found this helpful!