Skip to lesson

Sending JSON bodies and headers

A login or create request sends data, and the server must know what that data is and who sent it. With the wrong Content-Type or token, the same request gets 400, 401 or 415 instead of working.

Raw JSON body and the Content-Type header Postman adds

A raw JSON body is JSON text you type into the Body tab after choosing raw and then JSON. Postman then adds the header Content-Type: application/json, which tells the server how to read the bytes.

Change the method to POST, open Body, choose raw, pick JSON in the dropdown and type the JSON. The picture shows what goes on the wire.

Three Postman tabs fill one HTTP request. The Authorization tab becomes the line Authorization: Bearer plus the token. The Headers tab becomes your own header lines, such as X-Request-Id.

Example 1 · POST a raw JSON body to log in

Text
POST  http://localhost:8080/api/v1/auth/loginBody tab: raw, JSON{    "email": "admin@shoplite.test",    "password": "admin123"}
Response (Body tab, Pretty)
Status: 200 OK

{
    "accessToken": "sl_at_admin_7Kq2Vx9P",
    "tokenType": "Bearer",
    "expiresIn": 3600
}

What this code does

  • Choosing JSON in the Body dropdown made Postman add Content-Type: application/json, so the server read the email and password.
  • The answer is an access token: a string that proves you logged in. The next requests send it in the Authorization header. These are test accounts of the practice API; never paste a real password into a shared collection.

The dropdown at the end of the row says Text at first, so you must change it. Postman colours the JSON and underlines mistakes such as a missing quote before you send. Without the Content-Type header, a careful API refuses the body even when the JSON is perfect.

The Body tab also offers form-data and x-www-form-urlencoded, which HTML forms and file uploads use. A JSON API does not understand those types, so for REST APIs that take JSON, always use raw → JSON.

Custom headers and the hidden auto-generated ones

Hidden headers are the headers Postman adds on its own, such as Host, User-Agent and Postman-Token. Click the small hidden link above the Headers table to see them.

The Headers tab holds headers you add yourself, such as Accept or X-Request-Id. Postman adds more behind the scenes; the example shows the real list.

Example 2 · The headers Postman really sends

Text
POST  http://localhost:8080/api/v1/echoHeaders tab (yours)  X-Request-Id   fest-2026-001Body tab: raw, JSON (the same login JSON as Example 1)
Sample output (your Postman-Token and version differ)
Status: 200 OK

Request line and headers the server received:
POST /api/v1/echo
X-Request-Id: fest-2026-001
Content-Type: application/json
User-Agent: PostmanRuntime/7.39.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 856836d6-21e3-4dc7-9530-949fa58814a8
Host: localhost:8080
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 66

What this code does

  • The practice API's /echo endpoint sends back the request it received. Only X-Request-Id came from the Headers table; the other ten headers were added by Postman.
  • Content-Type and Content-Length appear because there is a body. Postman-Token changes on every send and User-Agent names the Postman version, so your values differ.

The hidden ones are Postman-Token, Host, User-Agent, Accept, Accept-Encoding and Connection, plus Content-Type and Content-Length when there is a body. User-Agent: PostmanRuntime/... is how a server tells Postman from a browser, and Postman-Token is a random id added to every send. A header you type yourself wins over the hidden one with the same name.

If a request works in Postman but not from your own code, compare the hidden headers with what your code sends: usually a missing Content-Type or Authorization header is the difference.

Header names ignore case: content-type and Content-Type are the same header.

The Authorization tab: Bearer token and Basic auth

A bearer token is a login token, usually from a login call, sent as Authorization: Bearer <token>. Whoever holds the token gets in, so it must stay secret.

Choose Bearer Token in the Authorization tab and paste the token. The examples show Bearer, Basic, no token and the wrong role.

Example 3 · Bearer, Basic, nothing, and the wrong role

Text
1) GET   http://localhost:8080/api/v1/auth/me   Authorization: Bearer Token  sl_at_admin_7Kq2Vx9P2) GET   http://localhost:8080/api/v1/auth/me   Authorization: Basic Auth    admin@shoplite.test / admin1233) GET   http://localhost:8080/api/v1/auth/me   Authorization: No Auth4) POST  http://localhost:8080/api/v1/products  Authorization: Bearer Token  sl_at_asha_3Ld8Wm4R (a customer)         Body: raw, JSON  {"sku":"BK-RDPD","name":"Rich Dad Poor Dad","categoryId":5,"price":299.00,"stock":40}
Responses (Raw view; request 3 also shows two headers)
1) Bearer Token
Status: 200 OK

{"email":"admin@shoplite.test","name":"Store Admin","role":"ADMIN"}

2) Basic Auth
Status: 200 OK

{"email":"admin@shoplite.test","name":"Store Admin","role":"ADMIN"}

3) No Auth
Status: 401 Unauthorized

Content-Type: application/problem+json
WWW-Authenticate: Bearer realm="shoplite"

{"type":"https://shoplite.example/problems/unauthorized","title":"Unauthorized","status":401,"detail":"Sign in to use this endpoint.","instance":"/api/v1/auth/me"}

4) Bearer Token of a CUSTOMER, on POST /api/v1/products
Status: 403 Forbidden

{"type":"https://shoplite.example/problems/forbidden","title":"Forbidden","status":403,"detail":"You do not have permission to do this.","instance":"/api/v1/products"}

What this code does

  • Requests 1 and 2 prove the same identity in two ways. For Basic, Postman sent Authorization: Basic YWRtaW5Ac2hvcGxpdGUudGVzdDphZG1pbjEyMw==, which is just admin@shoplite.test:admin123 in Base64.
  • Request 3 has no login, so 401 plus WWW-Authenticate: Bearer tells you which login to send. Request 4 has a valid login with the wrong role, so the answer is 403, not 401.

The Authorization tab fills the Authorization header for you. Basic Auth takes a username and password and sends Authorization: Basic <base64 of username:password>. Base64 is only a way to write bytes as text, not encryption, so Basic auth is safe only over HTTPS. Without the tab you would type Bearer plus a long token into the Headers table by hand and get the space or the word wrong.

Two statuses tell login problems apart. 401 Unauthorized means "I do not know who you are": no token, a wrong token or an expired one. 403 Forbidden means "I know who you are, but you may not do this": logged in, but with the wrong role. A 401 response usually carries a WWW-Authenticate header naming the login type the server expects.

Predict the output

Which status comes back?

Read each request and pick the status.

Round 1 of 2

POST /api/v1/products
Content-Type: application/json
(no Authorization header)

PUT, PATCH and DELETE requests

PUT, PATCH and DELETE are the write methods for an existing resource: PUT replaces it as a whole, PATCH changes only the fields you send, and DELETE removes it.

In Postman you only change the method dropdown; the Body and Authorization tabs work as for POST. The examples PATCH one field, PUT a whole product and DELETE twice.

Example 4 · PATCH one field, then PUT the whole product

Text
Authorization: Bearer Token sl_at_admin_7Kq2Vx9P on all three, Body: raw, JSON1) PATCH  http://localhost:8080/api/v1/products/6   {"stock": 110}2) PUT    http://localhost:8080/api/v1/products/6   {"price": 1199.00}3) PUT    http://localhost:8080/api/v1/products/6   {"sku":"ACC-AD141","name":"boAt Airdopes 141","categoryId":4,"categoryName":"Accessories","price":1199.00,"stock":110,"isActive":true}
Responses (Raw view)
1) PATCH /api/v1/products/6
Status: 200 OK

{"id":6,"sku":"ACC-AD141","name":"boAt Airdopes 141","categoryId":4,"categoryName":"Accessories","price":1299.00,"stock":110,"isActive":true}

2) PUT /api/v1/products/6 with only a price
Status: 400 Bad Request

{"type":"https://shoplite.example/problems/validation-failed","title":"Validation failed","status":400,"detail":"The request has 5 invalid fields.","instance":"/api/v1/products/6","errors":[{"field":"sku","message":"is required"},{"field":"name","message":"is required"},{"field":"categoryId","message":"is required"},{"field":"stock","message":"is required"},{"field":"isActive","message":"is required"}]}

3) PUT /api/v1/products/6 with every field
Status: 200 OK

{"id":6,"sku":"ACC-AD141","name":"boAt Airdopes 141","categoryId":4,"categoryName":"Accessories","price":1199.00,"stock":110,"isActive":true}

What this code does

  • PATCH changed only stock and kept every other field. The response shows the whole updated product, so you can check it at once.
  • The PUT with only a price was rejected: PUT means "here is the full product", and five required fields were missing. The full PUT then worked.

Example 5 · DELETE twice

Text
Authorization: Bearer Token sl_at_admin_7Kq2Vx9P1) DELETE  http://localhost:8080/api/v1/products/142) DELETE  http://localhost:8080/api/v1/products/143) GET     http://localhost:8080/api/v1/products/14
Responses (Raw view)
1) DELETE /api/v1/products/14
Status: 204 No Content

2) DELETE /api/v1/products/14 again
Status: 404 Not Found

{"type":"https://shoplite.example/problems/not-found","title":"Resource not found","status":404,"detail":"Product 14 was not found.","instance":"/api/v1/products/14"}

3) GET /api/v1/products/14
Status: 404 Not Found

{"type":"https://shoplite.example/problems/not-found","title":"Resource not found","status":404,"detail":"Product 14 was not found.","instance":"/api/v1/products/14"}

What this code does

  • 204 No Content means the delete worked and there is no body to show; Postman's Body tab stays empty.
  • The second DELETE and the GET both say 404: the product is gone. The final state is the same however many times you delete, which is why DELETE is called idempotent.

PUT needs every field in its body, PATCH can send just {"stock": 110}, and DELETE usually has no body. The usual answers: PUT and PATCH return 200 OK with the updated resource, and DELETE returns 204 No Content with an empty body. A second DELETE of the same id returns 404 Not Found, because there is nothing left to delete.

The common mistake is to send a PATCH-style body with PUT. A careful API rejects it with 400 and lists the missing fields; a careless one silently wipes them. Read the response to know which kind of API you have.

Fixing 415 and 400 responses caused by the wrong body type

415 Unsupported Media Type means the server cannot read the body's format because the Content-Type is wrong. 400 Bad Request means it read the format, but the content is broken or invalid.

The body of the error response usually says which one it is. The example shows four rejected bodies and the fix for each.

Example 6 · Four rejected bodies and the fix

Text
POST  http://localhost:8080/api/v1/products   (Bearer Token sl_at_admin_7Kq2Vx9P)1) Body: raw, Text   (the dropdown was never changed)2) Body: form-data   (key sku = BK-RDPD)3) Body: raw, JSON   with a comma after "stock": 404) Body: raw, JSON   with "price": "299.00" (text, not a number)5) Body: raw, JSON   fixed:{    "sku": "BK-RDPD",    "name": "Rich Dad Poor Dad",    "categoryId": 5,    "price": 299.00,    "stock": 40}
Responses (Raw view)
1) Body: raw, Text
Status: 415 Unsupported Media Type

{"type":"https://shoplite.example/problems/unsupported-media-type","title":"Unsupported media type","status":415,"detail":"Content-Type text/plain is not supported. Send application/json.","instance":"/api/v1/products"}

2) Body: form-data
Status: 415 Unsupported Media Type

{"type":"https://shoplite.example/problems/unsupported-media-type","title":"Unsupported media type","status":415,"detail":"Content-Type multipart/form-data is not supported. Send application/json.","instance":"/api/v1/products"}

3) Body: raw, JSON, with a trailing comma
Status: 400 Bad Request

{"type":"https://shoplite.example/problems/malformed-request","title":"Malformed request","status":400,"detail":"The request body is not valid JSON.","instance":"/api/v1/products"}

4) Body: raw, JSON, with "price": "299.00"
Status: 400 Bad Request

{"type":"https://shoplite.example/problems/malformed-request","title":"Malformed request","status":400,"detail":"Field price must be a number.","instance":"/api/v1/products"}

5) Body: raw, JSON, fixed
Status: 201 Created

{"id":16,"sku":"BK-RDPD","name":"Rich Dad Poor Dad","categoryId":5,"categoryName":"Books","price":299.00,"stock":40,"isActive":true}

What this code does

  • Requests 1 and 2 never reached the JSON check: the Content-Type was text/plain or multipart/form-data, so the server answered 415 and named the type it wants.
  • Request 3 had the right type but broken JSON (the trailing comma), and request 4 had valid JSON with a value of the wrong type. Both are 400 Malformed request, and the detail says what is wrong.

Match the status to the cause:

  • 415 with text/plain → the Body dropdown still says Text; switch it to JSON.
  • 415 with multipart/form-data or x-www-form-urlencoded → you picked form-data; use raw → JSON.
  • 400 Malformed request → the body cannot be read: a syntax slip (a trailing comma, single quotes, a missing quote or brace) or a value of the wrong type, such as a price sent as the text "299.00" instead of the number 299.00.
  • 400 Validation failed → the JSON is fine but a value breaks a rule, such as a price of -5; the errors list names every broken field.

Fix the error

Fix the rejected request

Read the error, then pick the line that fixes it.

Round 1 of 2

The server cannot read the body format.

POST /api/v1/products
Authorization: Bearer <token>
Content-Type: text/plain
{"sku": "MOU-100", "price": 799}

Error

415 Unsupported Media Type
"detail": "Content type 'text/plain' is not supported."

Next step

Check your understanding

12 quick questions