Postman and database

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 Likes

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!!

1 Like

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 am also looking for this, were you able to get anything on this @MichalKotynski

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.

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!

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.

  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.

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:

https://www.postman.com/postman/workspace/postman-team-collections/collection/5922408-41044117-22a7-4f36-869c-13f73310b7e9?ctx=documentation

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.

5 Likes

@matt , I am using oracleDB, Do you have any solution???

You could take a look at:
https://www.oracle.com/database/technologies/appdev/rest.html

My solution is writing restful-api to return the data that I need.

good morning, I want to connect to a sybase base using postman, to consume your objects, please help me

anything that will allow me to connect to Apache Cassandra, please?