Bird
Raised Fist0
Postmantesting~20 mins

Raw body (text, XML) in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Raw XML Body Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Postman test script?
You send a POST request with raw XML body:
<note>
  <to>Alice</to>
  <from>Bob</from>
  <message>Hello</message>
</note>

In the Tests tab, you run this script:
const xml = pm.request.body.raw;
pm.test('Contains <to> tag', () => {
  pm.expect(xml).to.include('<to>Alice</to>');
});

What will be the test result?
Postman
const xml = pm.request.body.raw;
pm.test('Contains <to> tag', () => {
  pm.expect(xml).to.include('<to>Alice</to>');
});
ATest fails because the XML tags are case-sensitive and '<to>' is lowercase.
BTest fails because pm.request.body.raw is undefined in Postman scripts.
CTest passes because the raw XML contains the exact string '<to>Alice</to>'.
DTest throws a syntax error due to incorrect use of pm.expect.
Attempts:
2 left
💡 Hint
pm.request.body.raw contains the raw request body as a string.
❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies the raw XML body contains the tag with 'Hello'?
You want to check that the raw XML body sent in a POST request contains the tag <message>Hello</message>.
Which Postman test assertion is correct?
Apm.expect(pm.request.body.text).to.have.string('<message>Hello</message>');
Bpm.expect(pm.response.text()).to.include('<message>Hello</message>');
Cpm.expect(pm.request.body.raw).to.equal('<message>Hello</message>');
Dpm.expect(pm.request.body.raw).to.include('<message>Hello</message>');
Attempts:
2 left
💡 Hint
pm.request.body.raw holds the raw request body as a string.
🔧 Debug
advanced
2:00remaining
Why does this Postman test fail with 'TypeError: Cannot read property "raw" of undefined'?
You wrote this test script:
const xml = pm.request.body.raw;
pm.test('Check XML', () => {
  pm.expect(xml).to.include('<to>Alice</to>');
});

But when you run it, you get:
TypeError: Cannot read property "raw" of undefined

What is the most likely cause?
Postman
const xml = pm.request.body.raw;
pm.test('Check XML', () => {
  pm.expect(xml).to.include('<to>Alice</to>');
});
Apm.request.body.raw is only available in pre-request scripts, not test scripts.
BThe request body is not set or is empty, so pm.request.body is undefined.
CYou must parse the XML before accessing pm.request.body.raw.
DPostman does not support raw XML bodies in requests.
Attempts:
2 left
💡 Hint
Check if the request body is configured in the request.
🧠 Conceptual
advanced
2:00remaining
What is the best way to validate the structure of a raw XML body in Postman tests?
You want to verify that the raw XML body sent in a POST request has a specific structure, for example, it contains a <note> root with <to> and <from> child tags.
Which approach is best in Postman test scripts?
AParse the raw XML string using a DOM parser library and check the presence of tags programmatically.
BUse pm.expect(pm.request.body.raw).to.include() with multiple string checks for each tag.
CConvert the XML to JSON using an external tool before sending the request and test JSON instead.
DUse regex matching on pm.request.body.raw to find the required tags.
Attempts:
2 left
💡 Hint
Postman test scripts can use JavaScript libraries to parse XML.
❓ framework
expert
3:00remaining
How to automate testing of raw XML request bodies in a CI pipeline using Postman/Newman?
You have Postman collections with requests sending raw XML bodies. You want to run automated tests in a CI pipeline using Newman.
Which practice ensures reliable validation of raw XML bodies in this setup?
AInclude test scripts that parse pm.request.body.raw XML and assert structure/content using JavaScript XML parsers, then run Newman in CI.
BOnly check HTTP status codes in Newman tests, ignoring raw XML body validation to avoid complexity.
CConvert XML bodies to JSON before sending requests, so Newman can validate JSON easily.
DUse Newman environment variables to store XML strings and compare them as plain text in tests.
Attempts:
2 left
💡 Hint
Automated tests should validate XML content programmatically for reliability.

Practice

(1/5)
1. What is the main purpose of using the Raw body option in Postman when testing APIs?
easy
A. To send exact text or XML data as the request body
B. To automatically generate JSON data for the request
C. To create a graphical interface for the API
D. To validate the response status code

Solution

  1. Step 1: Understand Raw Body usage

    The Raw body option allows sending exact text or XML data in the request body without modification.
  2. Step 2: Compare with other options

    Other options like form-data or JSON editor do not send plain text or XML exactly as typed.
  3. Final Answer:

    To send exact text or XML data as the request body -> Option A
  4. Quick Check:

    Raw body = exact text/XML data [OK]
Hint: Raw body sends exact text or XML as is [OK]
Common Mistakes:
  • Confusing raw body with JSON auto-formatting
  • Thinking raw body generates data automatically
  • Using raw body to validate response codes
2. Which Content-Type header should you set in Postman when sending XML data in the Raw body?
easy
A. application/json
B. text/plain
C. multipart/form-data
D. application/xml

Solution

  1. Step 1: Identify correct Content-Type for XML

    XML data requires the Content-Type header to be application/xml so the server knows to parse XML.
  2. Step 2: Eliminate other options

    application/json is for JSON, text/plain is plain text, and multipart/form-data is for file uploads.
  3. Final Answer:

    application/xml -> Option D
  4. Quick Check:

    XML Content-Type = application/xml [OK]
Hint: Use application/xml header for XML raw body [OK]
Common Mistakes:
  • Using application/json for XML data
  • Omitting Content-Type header
  • Choosing text/plain for XML
3. Given this XML raw body sent in Postman:
<note>
  <to>Alice</to>
  <from>Bob</from>
  <message>Hello</message>
</note>

What will the server receive if the Content-Type is correctly set to application/xml?
medium
A. Plain text without any tags
B. A JSON object with keys 'to', 'from', and 'message'
C. The exact XML text as shown, including tags and content
D. An error because XML is not supported

Solution

  1. Step 1: Understand raw body with XML and Content-Type

    When raw XML is sent with Content-Type application/xml, the server receives the exact XML text including tags.
  2. Step 2: Eliminate other options

    The server does not convert XML to JSON automatically, nor strip tags or throw errors if XML is supported.
  3. Final Answer:

    The exact XML text as shown, including tags and content -> Option C
  4. Quick Check:

    Raw XML + application/xml = exact XML text [OK]
Hint: Raw XML with correct header sends exact XML text [OK]
Common Mistakes:
  • Assuming XML converts to JSON automatically
  • Thinking tags are removed in transmission
  • Believing server errors without checking support
4. You send this raw XML in Postman:
<user>
  <name>John</name>
  <age>30</age>
</user>

But the server returns a 400 Bad Request error. What is the most likely cause?
medium
A. The XML tags are invalid and malformed
B. Content-Type header is missing or incorrect
C. Raw body cannot send XML data
D. Postman does not support sending raw bodies

Solution

  1. Step 1: Check XML validity

    The XML tags are well-formed and valid, so the XML itself is not the issue.
  2. Step 2: Consider Content-Type header

    If the Content-Type header is missing or not set to application/xml, the server may reject the request with 400 error.
  3. Final Answer:

    Content-Type header is missing or incorrect -> Option B
  4. Quick Check:

    Missing/incorrect Content-Type causes 400 error [OK]
Hint: Always set Content-Type for XML raw body [OK]
Common Mistakes:
  • Blaming XML syntax without checking header
  • Thinking raw body cannot send XML
  • Assuming Postman lacks raw body support
5. You want to test an API that accepts plain text commands in the raw body. Which combination in Postman is correct to send the command START successfully?
hard
A. Set raw body to START and Content-Type to text/plain
B. Set raw body to {"command":"START"} and Content-Type to application/json
C. Set raw body to <command>START</command> and Content-Type to application/xml
D. Set raw body to START and Content-Type to application/xml

Solution

  1. Step 1: Identify data type expected by API

    The API expects plain text commands, so raw body should contain plain text like START.
  2. Step 2: Set matching Content-Type header

    For plain text, the Content-Type must be text/plain to inform the server correctly.
  3. Final Answer:

    Set raw body to START and Content-Type to text/plain -> Option A
  4. Quick Check:

    Plain text command needs text/plain header [OK]
Hint: Match raw body content with correct Content-Type header [OK]
Common Mistakes:
  • Sending plain text with JSON or XML headers
  • Wrapping plain text in JSON or XML tags unnecessarily
  • Using wrong Content-Type for plain text
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard