Postman send request with json request body from file

I am trying to send this text file, but I keep getting 415 error unsupported media type, in tests is just a 200 test and I commented pre-request script so I am not sure what am I doing wrong. I want to send data from a file as a json request body.

I have this in a text file

        "gender": 1,
        "company": "MyCompany",
        "name": "Doe",
        "firstname": "John",
        "phone": "0606060606" 

How can I achieve this?

Can you share more details about the API endpoint and what it expects? Is there any documentation that you can share?

If you’re sending a JSON payload, does the file need to be a .json file and not a .txt file?

Without more context about the API you’re using and the specific details about what a good request looks like, it’s going to be tricky to assist you here.

Do you mean like this?


If you want to read the data from the file to update the body, then that is a bit trickier as Postman doesn’t have native access to the local file system to be able to read the content of files. Whether its txt or json. You could potentially use the Collection runner and use a data driven test that way.

Yeah I meant to read the data from the file. I used runner for one POST request but i have 10 more with different data and I am not sure if I can store the info in one csv/json file?

I meant to read the data from the file. I cant give much info about it but i want to try to update the POST body with info I have in text file

Have a look at the collection runner and data driven testing.

You can either amalgamate all of the test data into a single json file (which would be my recommendation) or you could create a CSV file with each json file on a separate line as a string. You can use a minify app to shrink the json so it doesn’t wrap funny in the CSV file (so its all on one line).

As mentioned, you don’t have direct access to the file system, so you can’t just read any file. You’ll need to use the Collection Runner, or alternative would be to save your test data in a Collection or Environment Variable which you can access using a pre-request script and make changes to the body that way.