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.82k stars 838 forks source link

JSON POST request using app sends empty body #8455

Closed ChrisHacker closed 3 years ago

ChrisHacker commented 4 years ago

Describe the bug Setting Raw JSON for type in Body, putting valid JSON in the Body field, and sending. Endpoint receives request with right Content-Length and -Type but the Body is empty. Changing to Raw Text in Postman with the same body string generates a request that is received as expected. The cURL Code output by Postman for the two cases looks the same, other than the different Content-Type values.

To Reproduce Steps to reproduce the behavior: 1 Go to New Tab 2 Set up POST call 3 Click on Body 4 Set type to Raw and then pick JSON 5 Submit - body is empty on receipt at target 6 Leave type as Raw and pick Text 7 Submit - body is as expected (assuming you had properly formatted JSON to start)

Expected behavior Expecting JSON payload to be delivered when set Raw JSON as type and have valid JSON.

Screenshots Doesn't work: image

Works: image

App information (please complete the following information):

Additional context

shamasis commented 4 years ago

Is there a way for you to check if this is specific to the API you are calling. Try checking if this can be reproduced while calling https://postman-echo.com/post.

Perhaps your API expects a different content-type header for JSON? When you choose JSON, Postman auto sets the content type header to application/json based on RFC4627. However, many APIs expect text/json, text/x-json and so on. You may try providing them in your request headers.

Here are screenshots of what I tried and could not reproduce:

Screenshot 2020-05-11 at 3 10 15 AM Screenshot 2020-05-11 at 3 07 04 AM

ayyemichelle commented 4 years ago

I am having a very similar issue. I am using the latest version of Postman (7.24.0) for Windows 64 bit. I am trying to send a POST with a JSON body to an internal enterprise API that I am running locally. When I send the request the API receives an empty body as well. When I switch the type to Text I recieve a 500, since the company's server is expecting a body in the type application/json. However, when I get the Powershell code equivalent of my request from Postman and paste it in Powershell it correctly sends the request to the API with the complete body. This leads me to believe it is a bug in the Postman App.

ChrisHacker commented 4 years ago

Update: If I go into the Headers section and wrap the application/json Content-Type value in quotes, it works.

prakharvk commented 4 years ago

I am having same issue while sending JSON data through Postman, did you find any solution to this?

SabriH10 commented 4 years ago

@prakharvk Could you share some screenshots and more information on how you are making the POST request? ( omitting any sensitive information of course) I couldn't reproduce this issue on macOS.

Is this issue reproducible when using Postman Echo? https://docs.postman-echo.com/?version=latest. Thanks and looking forward to your response!

JessePreiner commented 4 years ago

Can confirm wrapping application/json in quotes works on v7.27.1

SabriH10 commented 4 years ago

@JessePreiner Are you also running on Linux? Could you confirm if the behaviour persists on v7.28.0 (latest version) when you don't wrap application/json in quotes?

JessePreiner commented 4 years ago

Seeing the same thing with 7.28.0 on Windows. Sending raw -> application/json, but from console appears to be sending form encoded. image image

@JessePreiner Are you also running on Linux? Could you confirm if the behaviour persists on v7.28.0 (latest version) when you don't wrap application/json in quotes?

JessePreiner commented 4 years ago

Still broken in 7.29.1 on windows. When viewing 'code' for the request, it appears to not add the content type at all.

mccannt commented 4 years ago

@JessePreiner I am not able to replicate this on Windows with v7.29.1

POST as JSON image image

POST as Text image image

What are we missing here?

JessePreiner commented 4 years ago

Another potential variable is this is after exporting and importing a collection. Next time I'm at a computer I'll try and get more details for you.

mccannt commented 4 years ago

Interesting. Please let us know how you make out and give us any additional steps.

mccannt commented 4 years ago

@JessePreiner Any updates on this?

kapbyte commented 4 years ago

Recordit GIF

Also having same issue (POST method returns empty request body) Windows with v7.33.1 Tried it on another app and works perfectly.

milmoe commented 4 years ago

I am having this issue with version v7.33.1 . any idea whats going on?

curl --location --request POST 'http://localhost:8080/api/cert/v1/certificate/operation?action=install' \ --header 'Content-Type: application/json' \ --data-raw '{ "operation_type":"install", "certificate_install_spec":{ "purpose":"testing", "public_addresses": [ "xx-44-236-144-165.ttt.com" ] } }'

kapbyte commented 4 years ago

I am having this issue with version v7.33.1 . any idea whats going on?

curl --location --request POST 'http://localhost:8080/api/cert/v1/certificate/operation?action=install' --header 'Content-Type: application/json' --data-raw '{ "operation_type":"install", "certificate_install_spec":{ "purpose":"testing", "public_addresses": [ "xx-44-236-144-165.ttt.com" ] } }'

No idea, same issue I had earlier on

cbasolutions commented 4 years ago

I was having this same issue.

The only thing which worked was setting the encoding to application/x-www-form-urlencoded. Then I stumbled upon this - https://stackoverflow.com/questions/57632438/post-is-empty-on-nginx. Problem solved.

In addition to better understanding what PHP was expecting, it seems that there is an issue with the way Postman is calling a URL without a trailing /. The POST data is getting lost in the redirect. E.g. https://site.com/endpoint is auto-redirected to https://site.com/endpoint/ and nginx isn't preserving the POST data. However, in cURL you can overcome this by using

curl --location --post301 --header 'Authorization: Basic $base64_encoded_string' --header 'Content-Type: application/json' --data-raw '{ "operation_type":"install", "certificate_install_spec":{ "purpose":"testing", "public_addresses": [ "xx-44-236-144-165.ttt.com" ] } }' http://localhost:8080/api/cert/v1/certificate/operation?action=install

I hope this helps.

yashodeepchikte commented 3 years ago

in the headers in postman you need to make sure the Content-Type: application/json
header is set if it is set to plain/text you will keep seeking an empty object

swapnilaryan commented 3 years ago

It only happens for me in localhost. And it happened today suddenly. I uninstalled and reinstalled yet the problem persists. but if i hit production urls it works..! I have no clue how I have tried editing all headers etc etc. And I copy curl from postman and hit via terminal it works... So, I am inclined towards that postman is sending null request body in case of localhost.. A pretty weird thing though but yeah its happening ...

This is localhost

Screen Shot 2020-10-28 at 4 15 36 PM

This is prod

Screen Shot 2020-10-28 at 4 17 17 PM
JessePreiner commented 3 years ago

In our case, one of our employees discovered it was a pre-request script we are using for token auth that was changing the content type.

martinvarta commented 3 years ago

Same issue for me. Its happen at remote and local host but its works with some saved entries by an unkown reason

ArtyomWS commented 3 years ago

Had the same issue, because I had errors in my json body. It was extra coma in body 2020-12-05_18-41

mccannt commented 3 years ago

Based on the comments I am seeing here, the issues are local to the users that are experiencing these issues and not an issue with the Postman application.

Closing this for the time being. If there is a verified issue with the app regarding this, please reopen with an example of the app malfunctioning.

Aomaf commented 3 years ago

im using node.js with express.js and this one solve it for me

app.use(express.json());
redmikegit commented 3 years ago

I'm having the same problem too. I'm getting blank data.

ijlalbm commented 3 years ago

You can add Content-Type with value application/json in headers, as well as uncheck Content-Type with text/plain value. It works for me.

postman_issue
mehanizm commented 3 years ago

same problem, win10, v8.0.10

response from postman-echo.com/post tells me that the body was empty, but if I copy cURL snippet and use it everything is OK

guys, I've spent several hours finding out what is the problem. but it is actually the postman bug, very bad bug that makes users suffer.

please, do smth with it

kimbersHolland commented 3 years ago

I just started using Postman and I ran into this issue testing a custom REST API in Salesforce. I haven't been able to resolve it.
I was so excited learning to use Postman. Now I am frustrated that such a vagrant issue has been swept under the carpet. Time to look for another toolset... :(

JSON BUG

mccannt commented 3 years ago

@kimbersHolland Can you open up the Postman console and ensure the data is being sent in and received. In many cases, we have seen the issue is at the end of the service being called.

kimbersHolland commented 3 years ago

Hi Trent M, Thank you for the interest. You are right, I see in the Console that the Request Body is filled. So something is amiss in the hand-off...

What's odd is that all tests using the "Salesforce workbench REST Explorer" are successful. The JSON body is exactly the same in both tools.

[image: image.png]

[image: image.png]

On Mon, Apr 12, 2021 at 6:35 PM Trent M @.***> wrote:

@kimbersHolland https://github.com/kimbersHolland Can you open up the Postman console and ensure the data is being sent in and received. In many cases, we have seen the issue is at the end of the service being called.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/postmanlabs/postman-app-support/issues/8455#issuecomment-818287617, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARPXGCJHOIKVREOX5LQFLATTINYUNANCNFSM4M4Q57AA .

-- https://coastalcloud.us/2020-partner-innovation-awards-customer-success/

WillyRamirez commented 3 years ago

I'm having the same issue. All my GET calls work, but my POST calls have an empty request body when I console.log them in express hosted by Docker. The reason why I suspect my postman settings are wrong, is because the exact same call works when I cURL it...

works curl -H "Content-Type: application/json" -X POST -d '{"email":"test@test.com", "password":"admin"}' localhost:49160/login

Doesn't work image image

I checked my JSON in a linter, my content-type header is set to application/json, and the rest of the headers are disabled.

I'm on a Mac.

balamg commented 3 years ago

I'm facing the same issue. In my case, there is a redirection involved, and upon redirect, the Content-Length shows as 0 in the Postman Console. The Content-Length in the original request is correctly set. I'm using version 8.3.1 on MacOS

shamasis commented 3 years ago

I'm facing the same issue. In my case, there is a redirection involved, and upon redirect, the Content-Length shows as 0 in the Postman Console. The Content-Length in the original request is correctly set.

I'm using version 8.3.1 on MacOS

I haven't deep dived much. But straight from reading your sentence, it seems that you're possibly missing the general redirection behaviour. Every redirection, 301 and 302, results in eventually a GET call and GET does not have body. That's how redirections works. 😊

But, for testing, Postman allows you to change that behaviour too. Read https://support.postman.com/hc/en-us/articles/211913929-I-sent-a-POST-request-but-Postman-seems-to-be-sending-a-GET-request-

You can also check console (or turn off "follow redirections" settings) to see what final URL post redirection the request needs. And use that url instead.

balamg commented 3 years ago

Yes this is after "Follow Original HTTP method" turned ON

Johnthelegendary commented 3 years ago

im using node.js with express.js and this one solve it for me

app.use(express.json());

This Solution works like a magic

mylastore commented 3 years ago

I'm having the same issue. All my GET calls work, but my POST calls have an empty request body when I console.log them in express hosted by Docker. The reason why I suspect my postman settings are wrong, is because the exact same call works when I cURL it...

works curl -H "Content-Type: application/json" -X POST -d '{"email":"test@test.com", "password":"admin"}' localhost:49160/login

Doesn't work image image

I checked my JSON in a linter, my content-type header is set to application/json, and the rest of the headers are disabled.

I'm on a Mac.

Did you figure this out? For me also not sending the body at all

callbipin commented 3 years ago

I ticked all the headers then it worked. Then I realized you need to tick content-length.

mylastore commented 3 years ago

Never mind for me it was an error on my side. This is such a good library. Thanks

jkryanchou commented 3 years ago

Uncheck the content-length and it works.

lexcraw4d commented 3 years ago

Ah, I figured it out in mine hopefully if you are still stuck try this in your server.js app.use(express.urlencoded({extended: true})); app.use(express.json()); Here is a simple example for you to see as well (I'm a visual learner myself lol) image Hope this helps anyone in the future for reference! Thanks for all the recommendations 👍 💯

Happy coding!

lexcraw4d commented 3 years ago

I just started using Postman and I ran into this issue testing a custom REST API in Salesforce. I haven't been able to resolve it. I was so excited learning to use Postman. Now I am frustrated that such a vagrant issue has been swept under the carpet. Time to look for another toolset... :(

JSON BUG

Hello! Just replying to your post -- I posted what worked for me in the discussion if you want you can reference it and see if it helps. Also, I know you mentioned looking for another toolkit. While Postman is popular, you might want to look into Insomnia. Hope you find a solution if you haven't already!

EstebanGuerreroGuerrero commented 3 years ago

Estoy usando node.js con express.js y este lo resuelve por mí

aplicación . use ( express . json ( ) ) ;

Este me sirvio a mi, vale locooo !! En mi caso quedo así: this.app.use( this.usuariosPath , express.json() , require('../routes/usuarios-routes') );

SandraMarszalek commented 3 years ago

Run on the same problem today. Body contains a model like "MyArgs":[ { "arg1": "val1", "arg2: "val2" }]

I can see in console it's a valid model but on API side I can't get those valuse - they are both null.

lexcraw4d commented 3 years ago

Run on the same problem today. Body contains a model like "MyArgs":[ { "arg1": "val1", "arg2: "val2" }]

I can see in console it's a valid model but on API side I can't get those valuse - they are both null.

Did you try my method from screenshot?

ValkyrieIOW commented 3 years ago

I struggled with this for over a day. Eventually, after trying most of the suggestions above with no success, it turned out to be something wrong with my json, which I had copied and pasted from our API guide. Although it looked fine, there seemed to be something different about the curly braces causing it not to be accepted. I hope this helps someone.

SandraMarszalek commented 3 years ago

Run on the same problem today. Body contains a model like "MyArgs":[ { "arg1": "val1", "arg2: "val2" }] I can see in console it's a valid model but on API side I can't get those valuse - they are both null.

Did you try my method from screenshot?

Yes I did. It didn't worked. I downloaded lower version of Postman and it works fine.

lexcraw4d commented 3 years ago

Run on the same problem today. Body contains a model like "MyArgs":[ { "arg1": "val1", "arg2: "val2" }] I can see in console it's a valid model but on API side I can't get those valuse - they are both null.

Did you try my method from screenshot?

Yes I did. It didn't worked. I downloaded lower version of Postman and it works fine. Man, sorry to hear that glad you found a resolution! Happy Coding!

MrBirdJesus commented 3 years ago

I ran into this issue today and it's been a pain in my side all morning. I noticed that the body wasn't making it server-side for whatever reason and began digging into it.

I sent a POST request to https://postman-echo.com/post with the failing body and noticed that the endpoint was returning an escaped string rather than the JSON I was expecting. I tried manually setting the application type to no avail. I also downgraded to v7 and that too didn't help.

I then typed out the JSON body manually which... worked? I compared the two bodies - the one that I was initially using and the one that I had typed out using a tool. There was not a single character difference between the two. The only difference is that one was manually typed out by hand and one was copied from a Teams message. The version on Teams however was automatically styled - Keys, Values and Braces are all coloured. Is it possible that this styling is causing issues when the POST request is sent?

RussyCG commented 3 years ago

For those still suffering. I had the same issue as I had comments next to my post data variables using //. Worked fine going to the postman echo but was not happy when I tried to go to my local app.

samseen commented 3 years ago

I wouldn't know if this makes sense but I pasted my body text from someplace and after trying to figure out what the issue was, clicking on beautify made it work.