Backend receives null GUID instead of actual value

I’m working with a C# Web API and React TypeScript frontend. When I send a GUID from my frontend to the backend endpoint, the backend always gets an empty GUID (all zeros) instead of the actual value I’m sending.

Backend Controller:

[Route("FetchByUser")]
[HttpGet("{userId}")]
public async Task<ActionResult<List<Appointment>>> FetchByUser(Guid userId)
{
    Console.WriteLine(userId); // Shows: 00000000-0000-0000-0000-000000000000
    // rest of logic here
}

Frontend Service Function:

export const fetchAppointmentsByUser = async (userId: string) => {
    const endpoint = "http://localhost:5032/appointments/FetchByUser?userId=" + userId;
    console.log(endpoint); // URL looks correct in console
    // API call logic
}

Component Usage:

useEffect(() => {
    setAppointments([]);
    const loadAppointments = async () => {
        const testUserId = "A1B2C3D4-E5F6-7890-ABCD-EF1234567890";
        const result = await fetchAppointmentsByUser(testUserId);
        setAppointments(result);
    }
    loadAppointments();
}, []);

The URL in the browser console shows the correct GUID, but the backend parameter is always empty. No errors are thrown. What could be causing this issue?

yeah, exactly what growingtree said. your route template has {userId} so it’s looking for the guid in the path like /FetchByUser/A1B2C3D4-E5F6-7890-ABCD-EF1234567890. you’re sending it as a query param with ?userId= instead. that’s why it’s coming back null - the route isn’t matching.

You’ve got a mismatch between your route and how you’re calling it. Your controller has [HttpGet("{userId}")] which expects the GUID in the URL path, but your frontend is sending it as a query string parameter instead. That’s why the backend gets an empty GUID - the route parameter userId isn’t getting populated from the path. Change your frontend to "http://localhost:5032/appointments/FetchByUser/" + userId so the GUID goes in the URL path, not as a query parameter. This’ll match your route template and properly populate the userId parameter.

wait, are you mixing route parameters and query parameters? your controller expects {userId} in the route but your frontend sends it as ?userId=. shouldn’t your endpoint just be /FetchByUser/ + userId? what happens if you try that?