julianov's avatar

Laravel GET Endpoint Returns 404 Error Despite Existing Route: Trouble with URL Parameters

Hello All.

I've a problem with an endpoint in laravel because I get 404 route not found but the route exists! This is how I run the endpoint:

GET https://xxxxxxxxxxxxxx/public/api/v0/authentication/atp/getToken?age=24&code=uasdftgthysdfgljhaliuhsdflkjansdfñoihiubnoiajsdf623o5HwepCYitcgwSEs6jc.52f72d06-6a7d-47fd-9a6e-ceebf8c401d7.a446e778-2980-4353-8c5f-8338f85cd94d

But if I run

GET https://xxxxxxxxxxxxxx/public/api/v0/authentication/atp/getToken

I get

 {
      "error": "The age field is required. (and 1 more error)"
  }

So It looks like the problem it's because I send the age and code through the url but it's a get method endpoint so there must not be a problem there. Also running

php artisan route:list 

at console I get: ...... //others routes GET|HEAD api/v0/authentication/atp/getToken ...................................... AuthController@getValidationAfip GET|HEAD api/v0/authentication/atp/getUrl ............................................... AuthController@getUrlAfip GET|HEAD api/v0/authentication/antex/getToken .................................... AuthController@getValidationAnses GET|HEAD api/v0/authentication/antex/getUrl .. ........

This is the api.php

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers;
use Illuminate\Support\Facades\DB;

/*
 Others routes
*/
   
Route::prefix("/v0/authentication")->controller(Controllers\AuthController::class)->group(function () {

	Route::middleware(['auth:authentication'])->get('/atp/getUrl',[Controllers\AuthController::class, 'getUrlAtp']);
	Route::middleware(['auth:authentication'])->get('/atp/getToken', [Controllers\AuthController::class, 'getValidationAtp']);

	Route::middleware(['auth:authentication'])->get('/antex/getUrl',[Controllers\AuthController::class, 'getUrlAntex']);
	Route::middleware(['auth:authentication'])->get('/antex/getToken', [Controllers\AuthController::class, 'getValidationAntex']);

});

This is the controller method:

 public function getValidationAtp(Request $request): \Illuminate\Http\JsonResponse
    {
        try {
            $request->validate([
                'age' => 'required|numeric|regex:/^[0-9]{11}$/',
                "code" => "required|string",
            ]);
        dd($request->cuil);
        //..there is more code but I even not get the dd return

    }
0 likes
1 reply
jlrdw's avatar

Check things in your network tab.

1 like

Please or to participate in this conversation.