How to properly use curl POST JSON in my API requests? or What's the correct syntax for a curl POST J

14 Replies, 1875 Views

Hey! Yeah, the `-H "Content-Type: application/json"` header is *usually* required for curl post json requests. Some APIs are strict about it.

Try this:
```bash
curl -X POST https://api.example.com/data -H "Content-Type: application/json" -d '{"name":"test","value":123}'
```

If you're on Windows cmd, escaping quotes can be a pain. Use double quotes outside and escape inner ones with backslashes:
```bash
curl -X POST https://api.example.com/data -H "Content-Type: application/json" -d "{\"name\":\"test\",\"value\":123}"
```

Also, check out Postman or Insomnia for testing APIs—way easier than wrestling with curl post json syntax!

Messages In This Thread



Users browsing this thread: 1 Guest(s)