I’m trying to do something unusual with testing my REST API. I want to test if the correct data is written to the database on PostgreSQL. For this I need to send Postman request but before that I need to somehow send standard SELECT to my database and put the response in global variable or environmental variable. I was searching in www if anyone has such idea but I didn’t found anything.
Is this possible to do something like I want by using Pre-scripts in Postman?
Sorry if this question is trivial but I’m curious if I can do something like that with Postman.
Theoretically it may works. The logic process goes like that:
I’m checking some values in database by pREST api in pre-scripts, then I’m sending normal request by Postman and in assertions I’m checking again values using pREST.
But using this method I’m using two api’s. For now I’m using only one api because I made a temporary solution where I dont need two api’s. I created solution in my api where I’m sending specific parameters and this api is making request to db and serving values.
It is similar solution like using pREST, but I’m wondering if it is possible to write code in pre-scripts which will independently comunicate with database. Without using external api’s.
I dropped this subject temporarily because I didn’t found way to directly connect Postman to database. For this few testcases where I was forced to check something on database I created method with specific parameters which is triggering pre-writen database queries on the database/API side.
It is not the best solution but for now it satisfied my needs.
I’ll wait till someone find better way to do this or Postman Team add new features to the Postman.
Looking for this feature too.
Not quite sure that it is as “unusual” a testing scenario that original poster claims.
(Call API => Check DB is updated correctly)
For temporary solution that I’m using from time to time.
Create on your REST API new special method where you pass table name or watever parameters you need to your query. Your API must do the job and execute prepared queries.
create response for API asking database with queries, it must be easy for you to pass it to Postman variables for validation,
remember to limit acces to thim method due to potential harm that it may cause on your DB,
wait fot Postman to be fitted with DB communication in easy way.
I put together a collection/some documentation at the following link which shows how you can use some popular tooling for MySQL/PostgreSQL to get this going at a basic level: