Postman POST JSON: How to send JSON data to an API endpoint

preview_player
Показать описание


In the previous video in the Junior Developer 'How To Use Postman' series you learnt how to create a POST request and send form data as if from a HTML web form.

However sometimes a Postman POST JSON request is required as your API endpoint might not accept form-like data.

In fact it's quite common for JavaScript based web applications (that use Node as the backend for example) to be setup to send AND receive all of their data in JSON format.

In the tutorial i'll use a very basic PHP script to accept the JSON data, checking if a valid Postman POST JSON request is actually sent and returning an internal server error if not.

The Content-Type header is the key here as that is what will notify the PHP script that the data that is being sent is actually going to be in JSON format.

You will see that Postman actually sets the header for Content-Type automatically when you set the body of your request to JSON format. Of course you can manually set the Content-Type header yourself and check that it has been configured correctly in the Headers tab within Postman.

It is of course possible to send an empty body to the endpoint and still not produce an error but a more real-world application may have more in-depth data validation and error handling to prevent an empty body from being sent.

Related videos in the series:-
Рекомендации по теме
Комментарии
Автор

good grief. this is great! I asked how to do this in forum and got a convoluted answer involving pre-scripting that almost made me stop using the app. you nailed it in one go! good job! thank you.

IanSebryk
Автор

This was exactly what I needed, it was simple, short and relieved me of a lot of frustration, thank you!

amirsamir
Автор

my first appreciation comment on youtube thank you

raminhamza
Автор

Thank you very much! I spent a lot of time searching for libraries andd other stuff that didn´t work, but it just take me 5 minutes with your great explanation!!

gerardomorales
Автор

Thank you, it was the dropdown changing the Raw Body input to JSON, from text that was giving me my error. I can now continue my tutorial :)

nonamedlish
Автор

Thank you! I always use Insomnia, so I was a bit lost when using Postman to send JSON. Thanks for showing me how!

MrTutiplengo
Автор

Hello, may you show the way to send file but not using the form-data but using the raw with content-type application/json. As the one you did only send a statement.

mahdiys
Автор

Simple and straight to the point. Thanks very much!

MrQooje
Автор

Thank you so much Man! Appreciated, short and to the Point! Love you!

clashlogs
Автор

Thank you very much for this to the POINT tutorial. I understand now the whole payload JSON bit.

toolbelt
Автор

I need to send post request through apex, I dont know how to convert a specific clob into json in plsql code. Tried numerous ways, is there any way to post as json for a particular clob

SivanandRajarethinam-jp
Автор

How do you send the multiple requests at the same time? Is there any way to do that?

shinkevin
Автор

Thank you! This is exactly what I needed.

animaux
Автор

Thanks for the tutorial! Question, how do I (using PHP) can creat a script to send this JSON data to an API instead of using POSTMAN?

niltonc.
Автор

I just keep getting the error - "message": "Cannot send an empty message",
"code": 50006
I have data in there, but it still shows as empty - I copied exactly how you did it.
Any ideas?

donutgaming
Автор

short and precise...!! Exactly what i needed. Nice content

ayushbhardwaj
Автор

iwant to do the same but with nodejs so how can i do that

karanmanjhi
Автор

Hi, just to say this was very well done. Congrats and thanks for the useful lesson ...

ManuelGRivera
Автор

You saved my day, Thank you very much!

lakmalabeynayake
Автор

Hi, could you please guide me related to the http requests

harsheenajunejo