Tests Post Processor Assertion on HTTP Response Code

This might be a dumb question: but how I can setup the success of an HTTP request to Success or Failed based on the HTTP Response Status Code?

I get responses with 500 and 400 response codes and they are marked as success. I looked at the available assertion options and for HTTP requests they seem to be dealing mostly just with the http response body.

No worries! This is a very common question. You have two options to mark HTTP requests as Failed based on status codes:

  1. Response Validation (Recommended):

    • Enable “Validate Response in Run and Debug Case” and “Validate HTTP Status Code of Response” in your project settings
    • Make sure your API definition includes a 200 status code response template
    • Non-2xx responses (like 400/500) will automatically be marked as Failed
  2. Custom Script Assertions:

    • For more flexibility, use pm.test in custom scripts to create your own assertions
    • Failed assertions will mark the request as Failed

For more details, check our documentation: Validate responses - Apidog Docs





very nice - thank you much for the quick and comprehensive response. I will dig into this.

The “Validate Response in Run and Debug Case” option is missing in our Project Settings. We are under the Professional plan. Is Enterprise needed?

Therefore I can’t find a way to achieve my goal by using option 1.

Also I want to specify that the Tests I am talking about needing the Success/Failure validation setting based on Http Status Code are not generated from/referencing to Endpoints in the Default Module.

Hello! Thank you for the detailed explanation. Let me confirm your scenario: you added a step directly via “Add HTTP request” in Tests, rather than importing or applying an existing API from Endpoint or Endpoint debug case.

If that’s the case, we recommend using Method 2 to solve this. You can create script assertions in custom scripts using pm.test syntax, as shown in the image below.

[image]

yes, indeed that is what I did. Ok, I will try method 2