Postman and database


#1

Hello everyone,

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.


#2

Ok. I can suggest this:

  1. Use pREST to open api access to your database
  2. Call pREST api from postman script using pm.sendRequest API

How does that sound? Try it and let me know if you have success!!


#3

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.


#4

I am also looking for this, were you able to get anything on this @MichalKotynski


#5

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.


#6

Hi @MichalKotynski

I’m looking for the same solution that you asked, have you had any chance to get the solution to connect to the database and verify the response?

Please help!


#7

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)


#8

For temporary solution that I’m using from time to time.

  1. 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.

  2. create response for API asking database with queries, it must be easy for you to pass it to Postman variables for validation,

  3. remember to limit acces to thim method due to potential harm that it may cause on your DB,

  4. wait fot Postman to be fitted with DB communication in easy way.


#9

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:

There’s undoubtedly other libraries out there to make a REST API available for other database solutions if you aren’t using either of these two.