Verify database persistence after an API request
Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →
A POST response reports success and returns an order ID, but the database record is missing or has another value. Find that exact order and compare the persisted data with the requirement.
This workflow needs an active Pro license and a build containing Pro scenarios. See the edition details.
Define what POST must persist
In this illustrative scenario, POST creates an order with total 300 and returns orderId ORD-1042. The agreed database result is an orders row with status READY and total 300. These table names, fields and status are examples. Use your operation requirements and test database schema.
{"orderId":"ORD-1042","status":"READY","total":300}Why a successful response is not enough
The response shows what the request handler returned. Matching the submitted JSON does not by itself prove database persistence. Asynchronous processing can finish later. Agree a persistence deadline and read source so replica lag is not mistaken for lost data.

Connect to a PostgreSQL test database
Create a Checkcraft Pro connection to an existing test database using a SELECT-only account supplied by its owner. The address below illustrates a local training database. Replace its host, port and database name. A successful connection test confirms login, not access to the target table. DBeaver is not required.
jdbc:postgresql://localhost:5432/appFind the record by the API response ID
Save the SELECT below after adapting table and column names. For a standalone check, set the parameter to orderId=ORD-1042. In a scenario, orderId=${orderId} uses the value extracted by the preceding HTTP step. Parameters are passed separately from SQL. Selecting only the newest row can return another operation.

SELECT status, total FROM orders WHERE id = :orderIdCompare request, response and database values
For this example, expect exactly one row and enter the two expected columns below. Mark total as numeric so 300 and 300.00 compare equally. The expected 300 comes from the request requirement. Copying an incorrect 350 from the API response would only confirm agreement between two wrong results.
status=READY
total=300Wait for asynchronous persistence
If your operation is allowed 10 seconds to persist, an illustrative configuration is a 10000 ms timeout and 500 ms interval. This is not a universal service target. The check repeats SELECT until the expectation matches or time runs out. It does not repeat the creating POST. Attach the saved database check after the HTTP request in a Pro scenario.
Distinguish missing records from wrong values
For zero rows, first check orderId, environment and timeout. For a row with a different status or total, record the expected and actual values. Treat connection and permission failures separately from an absent record. Share the operation ID, service versions and permitted query results with the developer.
Choose a repeatable verification workflow
A one-off SELECT can run in DBeaver; code or AI assistance can help automate it. This Checkcraft Pro workflow keeps the database query, expectations and execution order alongside API checks. Correlated logs can help locate processing failures. It verifies one operation, not an entire warehouse. Compare your test result with an agreed requirement.
Which checks run in the database after a request
| Check | SQL idea | What it catches |
|---|---|---|
| Record exists | SELECT count(*) by id from the response | 201 without a save |
| Fields match the request | SELECT the needed columns | Lost or distorted values |
| No duplicates | GROUP BY key HAVING count(*) > 1 | A request processed twice |
| Related tables filled | JOIN on the foreign key | Order without lines, payment without order |
| Status moved correctly | status value and change time | Stuck operations |
| Delete worked | Record absent or deleted_at set | Deletion only in the response |
Query examples
-- the record by id from the API response
SELECT id, status, total, currency
FROM orders
WHERE id = :orderId;
-- order lines and their sum
SELECT count(*) AS lines, sum(amount) AS total
FROM order_items
WHERE order_id = :orderId;
-- duplicates in the last hour
SELECT external_id, count(*)
FROM orders
WHERE created_at > now() - interval '1 hour'
GROUP BY external_id
HAVING count(*) > 1;Use parameters like :orderId instead of string concatenation. The query is safer and easy to reuse with different values.
Database access for tests
- Test database only, never production.
- A separate account with SELECT only. A check needs to change nothing.
- Password in connection settings or an environment variable, not in the check text.
- Without direct access, ask developers for a read replica or a test-only API method.
Test data and isolation
Database checks break when several runs write the same data. Three habits help.
- A unique marker per run, such as a comment or email with the run number. Search by it.
- Look up by the id from the response, not "the last row in the table". The last one may be someone else's.
- Clean up after the run or use a separate schema for automated tests.
If the record appears only after a queue is processed, repeat the query at an interval up to a set timeout. A single check right after the response gives a false failure.
Response, logs and database together
The most reliable check of an operation looks at three places: the API response, the log record by traceId and the database row. The response shows what the service said, the log what it did, the database what remained. Linking a log to a request is covered in what a traceId is.
Typical mismatches between response and database
| What you see | Likely cause | Where to look |
|---|---|---|
| 201, no record | The transaction rolled back after the response | Service logs by traceId |
| Record exists, amount differs | Recalculation or rounding on the server | Calculation code, currency, discounts |
| Two identical records | Request repeated by client or queue | Idempotency key, retry logs |
| Status stuck | A background job did not run | Queue, handler logs |
| Time shifted by 3 hours | Different time zones | Column type and driver settings |
Waiting for an asynchronous write
If the record appears after a queue is processed, the check must repeat the query with a pause until a timeout.
for attempt in range(10): # up to 10 seconds
row = db.fetch_one("SELECT status FROM orders WHERE id = %s", order_id)
if row and row["status"] == "PAID":
break
time.sleep(1)
else:
raise AssertionError("order did not reach PAID in 10 seconds")Set the timeout from requirements or measurements on the stand. Too short gives false failures, too long hides degradation.
If the database is not SQL
In MongoDB the same check is a document lookup by the id from the response.
db.orders.findOne({ _id: ObjectId("6561f0c2a1b2c3d4e5f60718") }, { status: 1, total: 1 })In Redis you check the key and its lifetime with GET and TTL. The principle is the same: find the object by the id from the response and compare fields with the request and requirements.
Frequently asked questions
Why check the database if the API returned 201?
The response shows what the handler said. The record may not be saved, saved with other values or saved twice.
What permissions does a database check need?
SELECT only, on a test database. A check needs to change nothing.
Start with Free, add Pro for this workflow
This workflow needs Pro. Requests, response rules and log correlation are free with no time limit, so you can try the app first and add Pro when you need it.
Download FreeDownload and first runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
Start with the linked example and compare its result with your own test requirement.