Then you’re not passing the credentials correctly. You can search for examples of how to pass them in the header.
But I just tested this one:
DISCOURSE_API_KEY==API_KEY=
DISCOURSE_API_USER==API_USER=
curl -s -X GET --header "Api-Key: $DISCOURSE_API_KEY" --header "Api-Username: $DISCOURSE_API_USER" https://example.com/admin/dashboard.json