---
sourceDocument: Brazil API Reference
sourceDocumentLink: https://www.servicenow.com/docs/r/api-reference

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Control request and response content type

# Control request and response content type {#ariaid-title1}

Release version: Brazil  
Updated September 10, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Control request and response content type

This feature controls which content types are allowed in scripted REST API requests and responses within ServiceNow.
By default, scripted REST APIs support JSON and XML content types, including user-defined custom types that are subtypes of JSON or XML.
Proper handling of content types ensures correct processing of request bodies and appropriate response formatting.
Show full answer Show less  

## Key Features

* **Supported Content Types:** Default support includes `application/json`, `application/xml`, and `text/xml`. Custom JSON or XML subtypes like `application/vnd.collection+json` are also supported.
* **Request Body Access:** If the request body format is not a JSON or XML subtype, access the request body only through the `dataStream` field to avoid server errors.
* **Default and Resource-Level Settings:** You can configure default accepted content types for requests and responses at the API level using the Default supported request and response formats fields. These defaults can be overridden per resource using the Supported request and response formats fields. Note that Supported request formats apply only to PUT, POST, and PATCH methods.
* **Wildcard Content Types:** Wildcards can be used to specify valid content types. The percent sign (%) matches a single character, and the asterisk () matches zero or more characters, enabling flexible content type specifications.
* **Handling application/x-www-form-urlencoded:** When accepting `application/x-www-form-urlencoded` content, the key-value pairs are accessible as a JSON map via `request.queryParams`. These parameters combine query string and body parameters for easy access.
* **Binary Response Handling:** For sending binary data in responses, set the response content type accordingly and write the binary stream directly using the `RESTAPIResponseStream` object obtained via `response.getStreamWriter()`.

## Key Outcomes

* Ensures that scripted REST APIs correctly accept and respond with supported content types, preventing errors caused by unsupported formats.
* Enables customization of accepted content types at both the API and resource levels, providing flexibility in API design.
* Provides practical guidance on managing form-urlencoded data and binary responses, which are common in integration scenarios.
* Improves error handling by responding with appropriate HTTP error codes (406 or 415) when unsupported content types are used.  
Controls which content types are allowed in scripted REST API requests and
responses.  
By default, scripted REST APIs support `application/json`, `application/xml`, and `text/xml`. User-defined custom content types (with `json` or `xml` subtypes) are also supported. For example, `application/vnd.collection+json` and `application/vnd.adobe.xdp+xml` are treated as JSON and XML, respectively.  
Important:  
If the request body format is not of a `json` or `xml` subtype, use only the request body `dataStream` field to access the request body. Using request body `data`, `dataString`, `nextEntry()`, or `hasNext()` with a non-json or non-xml format results in a 500 error response.

## Setting defaults {#c_SpecifyContentType__section_q3k_j3x_23b}

You can set default values for the API using the Default supported request formats and Default supported response formats fields.
These fields define acceptable values users can pass in the Content-Type and Accept request
headers, respectively. If a requesting user specifies an Accept or Content-Type header not
supported by the API or resource, the instance responds with an HTTP error code of
406 or 415.  
You can override these values for each resource using the Supported request formats and Supported response formats on the Scripted REST Service form.  
Note:  
The Supported request formats field appears only for PUT, POST, and PATCH resources.

## Using wildcard values {#c_SpecifyContentType__section_qdv_g3x_23b}

You can use wildcard values when specifying valid content types.

* To perform a single-character wildcard search, use the percent sign (%) character. This wildcard finds words that contain any one character in place the percent-sign-character. For example, to find words such as text or test, search for: <kbd class="ph userinput">te%t</kbd>.
* To perform a multiple-character wildcard search, use the asterisk (\*) character. This wildcard finds words that contain zero or more characters in place of the asterisk-character. For example, to find words such as planned or placed, search for: <kbd class="ph userinput">pl*d</kbd>.
{#c_SpecifyContentType__ul_rdz_1mv_32b}

## Using the x-www-form-urlencoded content type {#c_SpecifyContentType__section_cww_b3x_23b}

If a REST API or resource accepts the `application/x-www-form-urlencoded`
content-type, you can retrieve the urlencoded values provided in the request as a JSON map.
You can then supply these urlencoded key-value pairs as query parameters, in the request
body, or both. They are combined and stored in the request parameters. Access these
parameters through the `request.queryParams` object.  
For example, if your API is defined to accept the `application/x-www-form-urlencoded` content-type and your API is implemented as follows,

    (function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

     response.setBody(request.queryParams);

    })(request, response);

... then the following request yields the respective response:

    POST to localhost:8080/api/now/some_api/some_resource?name3=value3&name4=value4

Body:

    name1=value1&name2=value2

Response:

    { "result":
        { "name4": [ "value4" ], "name3": [ "value3" ], "name2": [ "value2" ],
          "name1": [ "value1" ]
        }
    }

## Sending binary type in a response {#c_SpecifyContentType__section_iv5_pjx_23b}

When sending a binary type in a response, you must set the response content type and write
the binary stream directly using a `RESTAPIResponseStream` object. You can
access this object by calling `getStreamWriter()` on the response object. For
more information, see.

