API Test Cases: Ready-to-Use Examples for Login, CRUD and Errors
API test cases with examples: login, create, read, update, delete, errors and limits, each with its expected status and what to check, plus a checklist.
An API test case says which request to send, which status the server must answer, and what else must be true. This page lists ready-to-use examples for login, create, read, update, delete, errors and limits.
Many lists stop where everything goes well: send a good request, get a 200, done. Your users meet the other cases: the field left empty, the button clicked twice, the order that belongs to someone else.
What is an API test case?
Definition
An API test case is one request sent in a known situation, with everything its answer must hold.
- The situation counts as much as the request.
- Deleting an order that exists and deleting one that does not are two cases.
- Each case changes one thing, so a failure points at one cause.
- 1The requestCreate an order without its quantity.POST /orders
- 2The expected statusThe server refuses it as wrong data.400 · 422
- 3What else must be trueThe message names the missing field, and no order was created.GET /orders
The examples below use a shop's API with orders. Replace orders with clients, invoices or bookings: the cases stay the same.
API test case template, with a manual example
Copy these rows for each case. The second column shows one case filled in.
| Field | Example |
|---|---|
| Name | Create an order without its quantity |
| Before the test | Signed in as a customer. Note how many orders the list holds. |
| Request | POST /orders with an item and no quantity |
| Expected status | 400, as our API documents |
| What to check | The message names the field quantity. |
| Proof | GET /orders holds as many orders as before. |
| Clean up | Nothing to remove: no order was created. |
To run a case by hand, send the request, compare the answer with the rows, and write down what you found. That is a good way to get to know a new API. For the cases you want to keep, let a test do it at every build.
API testing status codes: what each one means
The meaning of a status is written in a public standard, RFC 9110.Click a status anywhere on this page to read its definition.
| Status | What it means | When a test expects it |
|---|---|---|
| 200 OK | The request succeeded. | Reading, and many changes. |
| 201 Created | In the standard's words, "the request has been fulfilled and has resulted in one or more new resources being created". | Creating. |
| 202 Accepted | Accepted, but not finished yet. | Work done later, such as an export. |
| 204 No Content | It succeeded, and there is nothing more to send back. | Deleting, and some changes. |
| 400 Bad Request | The server sees a mistake in the request itself. | A body it cannot read. In many APIs, wrong data too. |
| 401 Unauthorized | The request "lacks valid authentication credentials for the target resource". | No token, or one that is not valid. |
| 403 Forbidden | In the standard's words, "the server understood the request but refuses to fulfill it". | Signed in, without the right to do it. |
| 404 Not Found | Nothing was found there, or the server does not want to say that something exists. | An unknown id, or a deleted item. |
| 409 Conflict | There is "a conflict with the current state of the target resource". | In many APIs, a duplicate, or a change that came too late. |
| 422 Unprocessable Content | The server can read the request but cannot do what it asks. | In many APIs, data that breaks a rule. |
| 429 Too Many Requests | Too many requests in a given time.This one is defined in RFC 6585. | Going over a limit on purpose. |
| 500 Internal Server Error | Something unexpected happened inside the server. | Never. It is a bug to report. |
API test cases for a login page and its tokens
A login page sends an email and a password to the API, and gets a token back: a kind of pass, sent with every later request. Test the API behind the page first, then what the token opens.
| Test case | Expected status | What to check |
|---|---|---|
| The right email and password | 200 | The answer holds a token, and never the password. |
| A wrong password | 400401 | No token. |
| An email nobody registered | 400401 | The same status and the same message as for a wrong password. |
| No password at all | 400422 | The message names the missing field. |
| A protected request without a token | 401 | No data.The standard also asks for a WWW-Authenticate header. |
| The same request with an altered token | 401 | No data. Change one character of a real token. |
| The same request with an expired token | 401 | No data, until a new sign-in gives a new token. |
| A signed-in user without the right | 403404 | The action was not done: read the data back as someone who may see it. |
The second and third cases belong together.OWASP's Authentication Cheat Sheet says an application "must respond with a generic error message" whether the password was wrong or the account does not exist.OAuth 2.0 API testing has the cases of a sign-in service.
REST API test cases for creating data (POST)
| Test case | Expected status | What to check |
|---|---|---|
| A complete, valid order | 201 | An id, the values you sent, and often a Location header with the new address.Then read the order back. |
| A required field left out | 400422 | The message names the field, and no order was created. |
| A value of the wrong type, such as a word for a quantity | 400422 | The same: a clear message, and nothing created. |
| The smallest and the largest value allowed | 201 | Both are accepted, and saved as sent. |
| One below the smallest, one above the largest | 400422 | Both are refused, and nothing is created. |
| The same order reference twice | 409422 | One order exists, and the first one did not change. |
| A name with accents, an apostrophe or an emoji | 201 | Read back, the name is exactly the one you sent. |
| A field only the server may set, such as a paid status | 201400 | Refused or ignored, the saved order is not paid. |
An answer that says created is a promise. Reading the data back is the proof.
Test cases for reading data (GET): one item, lists, pages, filters
| Test case | Expected status | What to check |
|---|---|---|
| An order that exists, by its id | 200 | The values that matter, such as the item, the quantity and the total. The id alone proves little. |
| An id that does not exist | 404 | A clear message, and no data. |
| An id in the wrong form, such as abc | 400404 | A refusal, never a server error. |
| The whole list | 200 | The order you created is in it.items.length is the number you expect. |
| The second page | 200 | Its first order is not the first order of page one, and the page holds no more than its size. |
| A page past the last one | 200404 | An empty list, or the refusal your API documents. |
| A filter, such as open orders | 200 | An open order is in the list, and a paid one is not. |
| A filter that matches nothing | 200 | An empty list, not an error. |
For a filter or a page, create the orders the test needs first. A list that depends on data someone else left behind fails the day that data changes.
Test cases for changing data (PUT and PATCH)
In most REST APIs, PUT replaces the whole order, and PATCH changes only the fields you send.
| Test case | Expected status | What to check |
|---|---|---|
| Replace the whole order with PUT | 200204 | Read back, every value is the new one. |
| Change one field with PATCH | 200204 | That field is new, and every other one is as before. |
| Send the same PUT twice | 200204 | The result is the same as sending it once.The standard calls PUT and DELETE idempotent. |
| Send a value that breaks a rule | 400422 | Read back, the old value is still there. |
| Change an order that does not exist | 404 | Nothing was created. An API that creates it on a PUT answers 201 instead. |
| Make a change its state forbids, such as editing a shipped order | 409422 | The order did not change. |
| Save over a newer change made by someone else | 409412 | The newer change is still there. Only for an API that handles this case. |
Test cases for deleting data (DELETE)
For a delete that worked, the standard names three possible statuses: 200 with some content, 202 when the work is not done yet, and 204 with no content.Many APIs use 204 or 200: check yours.
| Test case | Expected status | What to check |
|---|---|---|
| Delete an order that exists | 200202204 | The status your API documents. |
| Read the deleted order | 404 | It is gone, and it left the list too. After a 202, ask again until it is gone. |
| Delete the same order again | 204404 | No server error. Nothing else was removed. |
| Delete an id that never existed | 204404 | The list holds as many orders as before. |
| Delete without the right to do it | 403404 | The order is still there. |
| Delete an order with an invoice | 204409 | Either the refusal or the clean-up your rules ask for, never half of it. |
Test cases for errors and limits
| Test case | Expected status | What to check |
|---|---|---|
| A body that is not valid JSON, such as a missing brace | 400 | A clear message, and nothing created. |
| A content type the API does not read | 415 | A refusal. Some APIs answer 400. |
| A method the address does not support | 405 | The standard asks for an Allow header with the methods that work. |
| A body or a file over the size limit | 413 | A clear refusal, and nothing saved. |
| Too many requests in a short time | 429 | The limit works.A Retry-After header may say how long to wait. |
| Every refusal on this page | Never 500 | The message is clear, and shows nothing of how the server is built. |
Test the limit on requests on a test server where you can set it low. How the API behaves under heavy traffic is the subject of a load test, not of these cases.
The case most lists forget: someone else's order
Ana creates an order, and the server gives it the number 1042. Ben signs in to his own account and asks for order 1042. Nothing on Ben's screen leads there, so no test of the screen ever tries. The API has to refuse him by itself.
GET /orders/1042
- Ana, who created the order200Her own order: the server gives it to her.
- Ben, signed in to his own account403 · 404Not his order: the server refuses. The test passes.
- Ben, when the rule is missing200He reads Ana's order. The test fails, before a customer finds out.
OWASP's list of API security risks starts with this one: API1:2023 Broken Object Level Authorization.In its words: "Attackers can exploit API endpoints that are vulnerable to broken object-level authorization by manipulating the ID of an object that is sent within the request." It calls the issue "extremely common in API-based applications".
Sign in as Ana and save her token as anaToken.Create an order with it and save orderId.Sign in as Ben and save benToken.
With Ben's token, read, change, then delete {{orderId}}.Expect 403, 404 each time, and check that the answer does not contain Ana's name.
Finish with Ana's token: her order is still there, unchanged. Then delete it.
Both statuses are right here.The standard lets a server that wants to hide an item answer 404 in place of 403.
How to automate API test cases without code
In GUI Test Studio, each case becomes one Call API step, or two with its proof. You send the real request, and the checks are written from the real answer.
| What the case says | What you set in the step |
|---|---|
| One exact status | That status, such as 201.When the server refuses on purpose, click Expect 401, or the status it gave. |
| One of several statuses | A list, such as 403, 404, or a range, such as 200-204. |
| A value is right | Click it in the answer, then Check This Value.Choose contains for a message. |
| A list has the right length | A check on items.length. |
| A header is there | A check on that header, such as Location: it exists, or it contains a text. |
| Nothing private comes back | A check on the whole answer: it does not contain the text. |
| The answer is fast enough | A check on the response time, in milliseconds. |
| The next request needs the new id | Save as Variable, then {{orderId}} in the steps that follow. |
| The work ends a moment later | Keep trying until it passes: the request is sent again every second, up to the time you allow. |
| Every case must run, even after a failure | Set If It Fails to Continue the test on the cases that do not depend on each other. |
API testing without code shows the steps in the editor, with the same orders.Tokens and passwords stay out of the test: write the name of a variable, as in environment variables in API testing.
Your team decides which cases matter.An AI assistant can then add them for you, through our connector: Claude, ChatGPT with Codex, or a local AI model we provide or you bring.Each case is a step on a timeline that people read without code.The engine sends the requests and checks the answers the same way at every run, on your computer or in your CI/CD pipeline.
The same test can also check what your users see: API testing vs UI testing shows how one test does both.
API testing checklist
Every request
- The exact status, not any success
- The values that matter
- The response time
- Nothing private in the answer
Every change
- The data read back afterwards
- The other fields left as they were
- The same request sent twice
- What the test created, removed
Every refusal
- A field left out, a wrong type
- Values past each limit
- Nothing changed on the server
- A clear message, and no 500
Every right
- No token, or an altered one
- An expired token
- A user without the right
- Another user's data, by its id
Short of time? Start with the requests that cost the most when they go wrong: those that take money, change an order or show personal data.
Key takeaways
- 1A case has three parts: a request, an expected status, and what else must be true.
- 2Change one thing at a time: a failure then points at one cause.
- 3Read the data back: after a success to prove the change, and after a refusal to prove that nothing changed.
- 4Expect the status your API documents: the standard gives the meaning, and APIs differ on 200 or 204, 400 or 422.
- 5Always test someone else's data: a second user who asks for the first user's order must be refused.
Questions
What are API test cases?
API test cases are the situations in which you test an API, each with a request, the status the server must answer and what else must be true. For example: create an order without its quantity, expect 400 or 422, and check that no order was created.
How do you write API test cases?
Start from one request and write the case where everything is right. Then change one thing at a time: a field left out, a wrong type, a value past its limit, no token, another user. For each case, write the expected status and how you prove what really happened.
What are the API test cases for a login page?
Test the right email and password, a wrong password, an unknown email and a missing password. Then call a protected address with no token, an altered token, an expired token, and the token of a user without the right. Check that a refused sign-in never gives a token.
Which status codes should an API test check?
The exact one your API documents for that case. Common ones are 200, 201 and 204 for a success, 400 or 422 for wrong data, 401 for a missing or invalid sign-in, 403 for a missing right, 404 for an unknown item and 409 for a conflict.
What is the difference between 401 and 403?
401 means that the server does not accept who you say you are: the token is missing or not valid. 403 means that the server understood the request and refuses it, for example because your account does not have the right. Some servers answer 404 to hide that the item exists.
Is it enough to check the status code?
No. A server can answer 201 and save the wrong quantity, or answer an error and create the order anyway. Check the values of the answer, then read the data back with a second request.
Can I run API test cases by hand?
Yes. Send each request, for example with curl, compare the answer with the case and write down the result. It suits a first look at a new API. Automate the cases you keep, because nobody repeats fifty requests by hand at every build.
Which API test case is forgotten most often?
A signed-in user who asks for data that belongs to someone else. Sign in as a second user, ask for the first user's order by its id, and expect a refusal. Then try to change and delete that order in the same way.


