Body isn't a json (just plain text) how do I get the body in custom script?

const response = pm.variables.get("$.11.response");


console.log("Body:", response.body);

This gives
“Body:”
undefined

I can find these in the documentation

Body (json)    {{$.<step id>.request.body.<field path>}}
Body    {{$.<step id>.response.body.<field path>}}```

I can assure you that I get a body back in step 11

Using client 2.7.2 (I know there’s a newer version 2.7.6 but if this isn’t fixed in these versions it’s not worth it to update for me because of certifications)

I’m probably just doing something wrong or this doesn’t work in Apidog

I can get the data from the stream and then decode the buffer into a string but seems like this should be standard behavior

// Get the response object of step 11
let response = pm.variables.get("$.1.response");

// Log the whole response to see everything
console.log("Full response:", response);

// Log the raw stream property
console.log("Body stream (raw):", response.stream);

// Decode the stream buffer into a string
if (response.stream && response.stream.data) {
    let buffer = Buffer.from(response.stream.data);
    let body = buffer.toString('utf8');
    console.log("Decoded response body:", body);

    // Try parsing as JSON (if applicable)
    try {
        let json = JSON.parse(body);
        console.log("Parsed JSON body:", json);
    } catch (err) {
        console.warn("Response body is not valid JSON.");
    }
} else {
    console.warn("No stream data found in the response.");
}

// Optional: Log response.body if it exists separately
console.log("Body Response (from .body):", pm.variables.get("$.1.response.body"));

// Throw an error for testing purposes
throw new Error("No roomstate added.");

Hi camachameleon , thanks for reaching out. We will look into this issue and get back to you soon.

Hi, camachameleon , could you please share the response headers content type for step 11 with us?

# HELP database_healthy Exposes the health of the database connection
# TYPE database_healthy gauge
database_healthy 1

# HELP http_requests_duration_seconds Histogram of HTTP request durations.
# TYPE http_requests_duration_seconds histogram
http_requests_duration_seconds_sum{method="GET",path="/health",status_code="200"} 318.01852710000134
http_requests_duration_seconds_count{method="GET",path="/health",status_code="200"} 25808
http_requests_duration_seconds_bucket{method="GET",path="/health",status_code="200",le="0.05"} 25539
http_requests_duration_seconds_bucket{method="GET",path="/health",status_code="200",le="0.2"} 25546
http_requests_duration_seconds_bucket{method="GET",path="/health",status_code="200",le="0.5"} 25807
http_requests_duration_seconds_bucket{method="GET",path="/health",status_code="200",le="1"} 25808
http_requests_duration_seconds_bucket{method="GET",path="/health",status_code="200",le="5"} 25808
http_requests_duration_seconds_bucket{method="GET",path="/health",status_code="200",le="+Inf"} 25808

http_requests_duration_seconds_sum{method="GET",path="version",status_code="200"} 0.022037400000000002
http_requests_duration_seconds_count{method="GET",path="version",status_code="200"} 8
http_requests_duration_seconds_bucket{method="GET",path="version",status_code="200",le="0.05"} 8
http_requests_duration_seconds_bucket{method="GET",path="version",status_code="200",le="0.2"} 8

step 11 and 1 are the same so don’t worry about that

Hi camachameleon , can you please share the response header screenshot of the step here or in DM?

I think because the response isn’t a json I can’t access response.body because you always have to use response.body.SOMETHING
you can’t just use response.body

Hi @camachameleon, thanks for your feedback. Currently, Apidog doesn’t support extracting raw format responses from previous steps directly. We’ve noted this requirement and will optimize it in future updates.

For now, you can add a step to extract variables in the post-processor of step 11, then use those variables in subsequent steps to achieve your goal.

Well I’m just going to use the script for this one but I’ll use this in the future.