0

How do I use Postman to send queries with body (in json format) and files (in multipart) format at the same time?

I think I should use Postman->Body->Raw although I can't find an example on the Web. Anyone can kindly teach me? Thank you!

Tan
  • 47
  • 7
  • Possible duplicate: https://stackoverflow.com/a/39037196/9192223 – hiren Dec 28 '22 at 10:43
  • @hiren it's not a duplicate. The json in your example is in form-data (with key) and not in body (without key). My API specification is such that the json is in body. Can this actually be done? – Tan Dec 28 '22 at 10:56
  • 1
    You can refer [here](https://stackoverflow.com/questions/39037049/how-to-upload-a-file-and-json-data-in-postman) for your question. – Sachin Mishra Dec 28 '22 at 10:57
  • 1
    So instead of form-data, you can select raw and add your json there. – hiren Dec 28 '22 at 11:01
  • yeah @hiren , agree. But how to select raw and add my json+multipart files? Can point me to a resource? – Tan Dec 28 '22 at 11:03
  • @SachinMishra , like what hiren has posted, I want the json to be in the body and not some form-data with key. – Tan Dec 28 '22 at 11:09

1 Answers1

2

In postman, set method type to POST.

Then select Body -> form-data -> Enter your parameter name (file according to your code)

On the right side of the Key field, while hovering your mouse over it, there is a dropdown menu to select between Text/File. Select File, then a "Select Files" button will appear in the Value field.

For rest of JSON data, you can click on raw and enter your JSON data there.

enter image description here

hiren
  • 1,067
  • 1
  • 9
  • 16