Newman "expected response to have status code 200 but got 500" in CI
The request ran, but a pm.test assertion checking pm.response.to.have.status(200) failed because the server answered 500. Newman reports it as an AssertionError and exits non-zero, failing the job.
What this error means
Newman prints an AssertionError line under the request name: "expected response to have status code 200 but got 500". The run summary shows 1 or more failed assertions and Newman exits with code 1.
GET Get user
1. Status code is 200
AssertionError: expected response to have status code 200 but got 500
at assertion:0 in test-script
inside "Get user"Common causes
The API genuinely returned a 500
The endpoint under test threw a server error (a bad env config, a missing migration, an unset secret), so the response status is 500 and the status assertion fails.
The environment or base URL points at the wrong service
The Postman environment baseUrl targets a service that is not the app under test, so the request hits an error page or a different app returning 500.
How to fix it
Read the response body Newman captured
- Run Newman with
--verboseso the full 500 response body prints in the log. - Fix the underlying server error (env var, DB migration, dependency) that produced the 500.
- Re-run so the status assertion sees a 200.
newman run collection.json -e ci.postman_environment.json --verbosePoint the environment at the app under test
Inject the correct base URL and any auth token through the environment so the request reaches the real service.
newman run collection.json \
--env-var "baseUrl=http://localhost:3000" \
--env-var "token=${{ secrets.API_TOKEN }}"How to prevent it
- Assert on a 2xx status only after the service is confirmed healthy.
- Inject baseUrl and auth token from the environment, never hard-code them.
- Log the response body on failure so a 500 is diagnosable from the CI output.