question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not posting body data

See original GitHub issue

I am trying send a post request but the json data in body attribute is not getting sent. I tried sending this request with Postman and it is working just fine.

Code:

const fetch = require('node-fetch')
fetch('https://test.instamojo.com/api/1.1/payment-requests/', {
  method: "POST",
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'X-Api-Key': 'xxx', 
    'X-Auth-Token': 'xxx'
  },
  body: JSON.stringify({
    purpose: 'FIFA 16',
    amount: '2500'
  })
}).then(res => res.json())
.then(data => console.log(data)).catch(e => console.log(e))

Error:

{ success: false,
  message: 
   { amount: [ 'This field is required.' ],
     purpose: [ 'This field is required.' ] } }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Lekocommented, Jan 15, 2019

@hrwndr I think the body should be encoded as form parameters, not JSON when the Content-Type is application/x-www-form-urlencoded. I hope this will help. Post with form parameters

0reactions
jimmywartingcommented, Jan 12, 2020

have been one year without any respond.

Read more comments on GitHub >

github_iconTop Results From Across the Web

post request not working, claims body data is not present ...
I've fixed the problem. There's 2 ways of fixing this. Solution 1: Add headers. fetch('http://localhost:3000/api/content', { method: 'post', ...
Read more >
Add a Request Body to a POST Request | API Connector
If it says invalid POST body data that means it isn't valid JSON. Maybe you've inadvertently copied in some extra characters, or maybe...
Read more >
Http.request not sending POST data? (SOLVED) - Defold Forum
request fires because I receive an e-mail as expected, but the POST data (which I intend to be the body of the e-mail)...
Read more >
POST - HTTP - MDN Web Docs
The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header....
Read more >
How do I post request body with Curl? - ReqBin
What is HTTP body? The HTTP body is the data sent in an HTTP message to the other side during client-server communication. Not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found