What to test at the API level even when the user interface works
Updated:
A form rejects an empty name and a user cannot see another customer’s order. That does not prove that the server enforces the same rules. A mobile app, a partner integration or a modified request can bypass the user interface.
Use API tests to check what the system must prevent and how it should handle failures. Negative quantities, unauthorised price changes and two bookings for the last available place are concrete scenarios. For each one, you need an expected response and an expected state after the request.
Start with a rule and its consequences
An endpoint list shows where you can send requests. A list of rules shows what must hold. For an order, that might mean correct pricing, available capacity and access restricted to authorised accounts.
For each rule, record an allowed case, an attempt to break the rule and a way to verify the result. “The API returned an error” is not enough if it also created a reservation or changed the record’s owner. For an allowed case, check that the operation actually made the requested change.
Use the specification, product rules and a discussion with the team as your starting points. If nobody knows whether a paid order can be cancelled, settle that rule first. A test should not treat whatever the server happens to do today as correct behaviour.
Permissions: objects, functions and individual fields
A signed-in customer may not have access to every order. Build a matrix of roles and operations, then add object ownership and the fields a user may read or change. Use at least two accounts with the same role but different data. This separates role checks from ownership checks.
| Area | Illustrative attempt | What to verify |
|---|---|---|
| Object | Customer A submits the ID of customer B’s order | Another customer’s content is neither exposed nor changed |
| Function | An ordinary account calls an administrator’s approval operation directly | The function does not run without the required permission |
| Reading fields | A customer retrieves their own order details | The response excludes internal notes intended for another role |
| Changing fields | A client adds ownerId or paid to the request |
The server prevents an unauthorised change of owner or payment status |
OWASP distinguishes these risks as object-level, object property-level and function-level authorisation. Less visible paths, such as exports and bulk updates, need the same checks.
Test unauthenticated access, relevant customer and internal roles, and boundaries between organisations if the system uses them. A hidden button does not prove that an action is forbidden. For a list endpoint, however, 200 with an empty result can be correct filtering behaviour. Define expectations from the contract, prohibited disclosures and side effects.
Permission to read does not imply permission to delete. Try the same identity across different operations and check fields in nested objects too. Before the negative test, confirm that order B exists and its owner can retrieve it. Otherwise, the test may pass simply because it uses an invalid ID, without exercising the actual permission check.
Inputs: value classes and boundaries
Form validation may prevent a negative quantity from being entered. The server must also handle requests that never went through that form. Divide inputs into valid and invalid groups, then select representative values from each.
For an illustrative rule allowing whole-number quantities from 1 to 10, test values such as 0, 1, 2, 9, 10 and 11. Missing fields, null, text instead of a number and fractional quantities are separate cases. This range is an example. Use the actual limits of your API.
For strings, check lengths at and beyond the limit, empty values and relevant characters. For dates, include an impossible date and a combination where the end precedes the start. Remember nested items, list sizes and fields that are not allowed. OWASP recommends validating both input format and meaning.
The OpenAPI specification helps with types and schemas. Whether a discount applies to a particular product or a customer may book a slot comes from business rules. Business logic data validation also examines relationships that valid JSON cannot establish.
Prices and other server-calculated values
For a purchase, test a request with an altered price, discount or total. If the server determines these values, the client must not be able to override them arbitrarily. Depending on the contract, the server may reject or ignore a field that is not allowed. The resulting order must still contain correctly calculated values.
Derive the expected price independently from agreed rules and controlled data. Check line items, permitted discount combinations, currency and rounding. If you simply copy the amount from the response into your expectation, an incorrect calculation will go unnoticed.
Check the consequences too: the saved order and the amount sent to the payment service. A correct response with an incorrect payment still breaks the rule. OWASP describes server-side calculations and concurrency risks.
State transitions, concurrency and retries
List the allowed transitions, such as an order being created, paid and dispatched. Then try skipping a required step, repeating a completed operation or changing a record that has reached its final state. Whether cancellation is allowed depends on the product rule, not just the name of the state. This checks for workflow circumvention.
Sequential calls may miss a concurrency problem. For a single-use coupon or the last available place, prepare a test with coordinated concurrent requests. Check the final number of redemptions or reservations, not just individual responses. One successful run does not prove that a concurrency defect cannot occur.
If the API uses a key to recognise a repeated operation, cover the same key with the same data, changed data and the end of its validity window. Check the number of actual effects. Stripe’s rules illustrate why you need the specific integration contract. Behaviour can differ even between versions of the same API.
For temporary reservations, verify that capacity is released after expiry and test an attempt to complete an expired reservation. Time limits come from system requirements, as OWASP explains in its process timing guidance.
Failures and data consistency
Distinguish rejected input, dependency outages and cases where the client never received a response. A timeout does not necessarily mean the operation did not happen. For example, Stripe warns about unknown outcomes after network errors and some server errors. Without the right recovery procedure, a new request may produce a second effect.
For a payment gateway or warehouse service, simulate a rejection, a slow response and unavailability. Use a controlled substitute, often called a mock, or trigger a failure in a controlled test environment. You do not have to wait for a production outage. Supplement the substitute with a test of the real integration, since the model may simplify its behaviour.
Check results against the promised consistency. An atomic operation should not leave a partial business change. An asynchronous process may have a temporary state followed by recovery or compensation. In that case, the test checks the agreed final state within a defined time. Also inspect reservations, payments and sent messages, which may be difficult to reverse.
Error responses and sensitive data
For each negative case, define the agreed HTTP status, error code and a safe description of the problem. There is no single universal status code for every business rejection. The client needs enough information to distinguish the cause and respond correctly.
Responses must not reveal tokens, passwords, internal SQL or stack traces. OWASP’s error handling guidance separates client responses from internal diagnostics. Test the contents of error responses and check whether an overly generic message hides the rule that was violated.
Priorities and evidence that a test catches defects
Start with scenarios that could expose another customer’s data, affect financial operations or exceed capacity. Add rules that change often and defects that have already been fixed. Choose cases by impact, likelihood and differences in behaviour rather than running every combination without a clear purpose.
Keep a short map for selected rules: requirement, test, controlled data and evidence of the result. This also reveals gaps. A test for booking the last place needs a known amount of available capacity. A rejected-payment test needs a service that rejects payment in the agreed way. If setup cannot confirm these conditions, report a setup failure rather than a broken business rule.
When a test fails, distinguish an incorrect response, an incorrect saved state and an unavailable environment. The report should include the expectation, a safely recorded actual result and the necessary context. Changed data, an expired login or a delayed dependency can then be separated from a server defect without repeatedly testing the entire purchase manually.
For every test, ask whether it would fail if the server ignored the rule. In an isolated environment, you can deliberately change a value being checked or temporarily disable a particular check and observe the test’s response. This confirms that the specific assertion works. It does not establish complete security coverage.
Run stable critical scenarios in CI, the automated checks triggered by code changes. Use isolated data, controlled dependencies and reports that identify the broken rule, role and operation ID. How to test REST APIs covers the technical process of building a suite. When designing API tests, each case should show which rule it protects and how a violation would be detected.