Hi everyone, I’m pretty new to API testing in Katalon Studio and I’ve been stuck on this for hours.
I’m trying to test a POST request that creates a new user. I created a new Web Service Request object, set the method to POST, and pasted my JSON data directly into the HTTP Body tab (I selected the ‘text’ option because it looks like a big block of text).
When I click the test button, the server keeps firing back a 415 Unsupported Media Type status code.
I can see the data right there in the box, so I don’t understand why the server thinks the media type isn’t supported. What am I missing here?
The 415 Unsupported Media Type HTTP status code indicates that the server is refusing to accept the request because the payload format is in an unsupported format.
Even though you have pasted valid JSON into the HTTP Body tab, Katalon Studio defaults to sending requests as plain text (text/plain) unless you explicitly tell it otherwise. The API server expects a header called Content-Type with the value application/json. Because that header is either missing or set to plain text, the server rejects the request before it even looks at your JSON data.
The Solution
To fix this, you need to change how Katalon handles the body text or explicitly define the Content-Type header.
-
Open your Web Service Request object.
-
Go to the HTTP Body tab.
-
Instead of selecting text, click the dropdown and select string.
-
In the content type dropdown right next to it, select application/json. Katalon will automatically add the correct Content-Type header to your request.
Pro-Tip: Reusable Custom Keyword for Header Management
If you are building requests dynamically via scripting mode, it is highly recommended to use a robust, reusable method to handle headers. This ensures consistency across your test suites.
You can create a Custom Keyword in Katalon to automatically inject the correct JSON headers into a request object before it is sent.
Groovy
package com.api.helpers
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.testobject.TestObjectProperty
import com.kms.katalon.core.testobject.RequestObject
public class ApiHelper {
/**
* Standardizes a Request Object by ensuring the application/json Content-Type is set.
* @param requestObject The WS request object from your Object Repository
* @return The updated RequestObject with proper JSON headers
*/
@Keyword
def static RequestObject setJsonHeaders(RequestObject requestObject) {
// Retrieve existing headers
List<TestObjectProperty> headers = requestObject.getHttpHeaderProperties()
// Remove existing Content-Type if it exists to avoid duplicates
headers.removeIf({ property -> property.getName().equalsIgnoreCase("Content-Type") })
// Add the correct application/json header
headers.add(new TestObjectProperty("Content-Type", ConditionType.EQUALS, "application/json"))
// Update the request object
requestObject.setHttpHeaderProperties(headers)
return requestObject
}
}
How to use it in your Script View:
Groovy
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
// Load your request object
RequestObject request = findTestObject('Object Repository/MyApiRequests/CreateUser')
// Pass it through your custom keyword to fix the headers
request = CustomKeywords.'com.api.helpers.ApiHelper.setJsonHeaders'(request)
// Send the request safely
def response = WS.sendRequest(request)
WS.verifyResponseStatusCode(response, 201)
hi @hamzakhan
the “text” option sends the body with Content-Type: text/plain, which your API rejects. Switch the HTTP Body type dropdown from “text” to “json” (or “string” with content type set to application/json). That tells Katalon to send the proper Content-Type: application/json header automatically.
alternatively, you can leave the body as-is and manually add a Content-Type: application/json header on the HTTP Headers tab. Either way, the server needs that header to know how to parse the payload.
use the below instead of plain/text
Content-Type:application/json
A 415 Unsupported Media Type means the server rejected the request format, usually because the Content-Type header doesn’t match the JSON body.
Fix
Set the request to send JSON as application/json, not plain text.
In Katalon UI
- Open the Web Service Request.
- In the HTTP Body section, choose string if available.
- Set the body/content type to application/json.
- Make sure the request headers include:
Content-Type: application/json
Accept: application/json
Script example
import com.kms.katalon.core.testobject.TestObjectProperty
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.RestRequestObjectBuilder
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
def builder = new RestRequestObjectBuilder()
def request = builder
.withRestRequestMethod('POST')
.withRestUrl('https://your-api.example.com/users')
.withTextBodyContent('{"name":"John","email":"john@example.com"}')
.withHttpHeaders([
new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'application/json'),
new TestObjectProperty('Accept', ConditionType.EQUALS, 'application/json')
])
.build()
def response = WS.sendRequest(request)
println response.getStatusCode()
Why it happens
Even if the JSON is visible in the body editor, Katalon can still send it as text/plain unless the request metadata says it is JSON. The server checks the header first and may reject the request before parsing the payload
This is actually a very common API testing issue, especially as you are saying you are a beginner.
The key thing is that having JSON in the request body is not enough. The server also needs to know what type of content you’re sending.
In the Headers section, make sure: to have the content type
Since you’re entering raw JSON in the HTTP Body, make sure you’ve also added the header:
Content-Type: application/json
Some APIs also require:
Accept: application/json
If those headers are already present, check the API documentation to confirm the endpoint actually expects JSON.