postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.81k stars 839 forks source link

Store multiple request body (json) objects #9612

Open bkcummins opened 3 years ago

bkcummins commented 3 years ago

It would be very helpful to be able to store multiple request body (json) objects for a saved endpoint so that you could toggle between them for test data.

There is a similar option in AWS Lambda to store incoming test events. Thx in advance! https://aws.amazon.com/blogs/compute/improved-testing-on-the-aws-lambda-console/

I accomplish this now by saving the same endpoint configuration multiple times with different request bodies, but a drop down interface would be ideal.

Thx in advance for consideration!

Shared originally on the community forum. https://community.postman.com/t/store-multiple-request-body-json-objects/20315

lflucasferreira commented 3 years ago

Maybe this would work like saved examples. In this case, we could create multiple examples and use them in the body request. I work with an API with a lot of conditional fields and it is very annoying to create multiple requests for the same endpoint.

bkcummins commented 3 years ago

Super basic screenshot, but here's a rough idea.

01

knvpk commented 3 years ago

At first i thought adding example will solve the problem, but examples can't be run as normal request, for now i need to copy paste from example to request and run it. Multiple requests for same url would be very usefull.

thatbrainiac commented 3 years ago

Any news on when this may be implemented? :)

bridavis commented 2 years ago

This would be extremely helpfull.

RaviAH commented 2 years ago

I am waiting for this feature.. any update on this:-)?

webjunkie commented 2 years ago

At first i thought adding example will solve the problem, but examples can't be run as normal request, for now i need to copy paste from example to request and run it. Multiple requests for same url would be very usefull.

Maybe examples could be made "sendable" and possibly "request-only". That would solve it.

dinuvld commented 2 years ago

Indeed this would be a very useful addition. We are looking at automatically generating monitors from an OpenAPI spec that has multiple example bodies per request. Being able to natively support this instead of creating multiple requests using the Collection SDK would be an incredible time saver.

ewilliams-zoot commented 2 years ago

I haven't actually implemented this myself, but as a work-around, I could see using Collection variables for this. In one variable, you store an index. In another variable you can store a JSON string that has an array of your test cases - called testCases - like so:

{
  "testCases": [
    "{\"name\": \"Bob\"}",
    "{\"name\": \"Alice\"}"
  ]
}

Then in a pre-request script for the Request, you can do something like this, maybe? Changing the index variable when you want to switch to a different body.

const testCases = JSON.parse(pm.collectionVariables.get("testCases")).testCases;

pm.request.body.raw = testCases[pm.collectionVariables.get("index")];

Edit: added .testCases to the end of the first JS line

blackwiz4rd commented 2 years ago

This feature would be awsome as state above to run automated testing with different bodies.

MrWolfPST commented 2 years ago

This is a must have feature. It should permit store not only the Body section but also Headers and Params, included Query Params and Path Variables.

yatw commented 2 years ago

@ewilliams-zoot this work around is hard to maintain in practice. Each API request json string is not going to be nicely display in 1 line and editing something in it is error prone.

ewilliams-zoot commented 2 years ago

@yatw Yes, I agree 100%, but it's a work around that seems to have worked for me. I have since tried it on a project, and it is cumbersome to be sure.

Buyukcaglar commented 2 years ago

Please bring this functionality to Postman, it really would make our lives a lot easier. Thanks. Onur

sksingtn commented 2 years ago

This feature would really help.

tylerthecoder commented 1 year ago

I would like this feature a lot. Any update?

ewilliams-zoot commented 1 year ago

@tylerthecoder They introduced a CLI with their latest updates; I haven't looked into it yet, but that may have the capability people in this thread are wanting. You can at least integrate whatever functionality they have in the CLI with a scripting language of your choice. I'm not sure that is better than my other suggestion above, to be honest.

talesid5 commented 1 year ago

I specially googled for this feature that led me to this thread... Would be an amazingly helpful feature

mathematikoi commented 1 year ago

this would be a great feature :D

g14wx commented 1 year ago

It will be super helpful, sometimes we need to leave different scenarios with different JSON Objects

kanchansapkota27 commented 1 year ago

Still looking forward for this feature

giridharvc7 commented 1 year ago

You can save these payloads as Examples to document these different bodies and you can consume these trying the examples out. Attaching a short video on how i'd approach this. Let us know if this makes sense.

https://user-images.githubusercontent.com/1040583/221112612-ab608460-0896-47ae-8c0c-f2f62c62bcfe.mov

Buyukcaglar commented 1 year ago

You can save these payloads as Examples to document these different bodies and you can consume these trying the examples out. Attaching a short video on how i'd approach this. Let us know if this makes sense.

This is somewhat convoluted way of achieving the requested functionality but it works. Thanks for sharing. Though I'd prefer directly saving and using multiple request bodies. Until it is implemented properly, this is the way to go.

giridharvc7 commented 1 year ago

Examples serve as scenarios and documenting what the API is capable of, and thus seems like the perfect place to store multiple json objects for a given request. This way its also easier for your collaborators to understand. Also looking from the previous comments, it seems like one of the blockers all these days was the inability to send examples - this was addressed recently in a release. Would love to know your use cases in depth to see if this needs a different solution.

webjunkie commented 1 year ago

Linking this issue (sendable examples): https://github.com/postmanlabs/postman-app-support/issues/3694#issuecomment-1433299057

rpedroni commented 1 month ago

We use examples for this and works perfectly for showcasing different payloads an endpoint can accept