Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

Create and configure a scripted REST API for your custom chat integration

Create a scripted REST API, add a scripted REST resource, set security and content negotiation, and set REST API rate limits.

Before you begin

Map rich controls to the channel in your custom chat integration.

Role required: admin

Procedure

  1. Create the REST API.

    1. Navigate to All > System web services > Scripted Web Services > Scripted REST APIs.

    2. Click New.

    3. On the form, fill in the fields.

FieldDescription
NameName of your API. For example, `ACME Mobile App Chat Adapter`.
API IDAPI identifier. For example, `acme_chat`.
Protection policyThe protection policy for the script.- Read-only: Script is viewable only. - Protected: Users with password permissions can edit the script.
ApplicationThe application containing the script record. Global is selected by default.
API namespaceThe namespace the API belongs to. The value depends on the current application scope.
4.  Click **Submit**.

5.  Open the new record, navigate to **Related Links** and click **Enable Versioning**, and then click **OK**.

    Click **Update** to save your changes.
  1. Add a scripted REST resource to your new REST API.

    The scripted REST resource defines the scripted REST API definition that you created.

    1. Open the REST API record you created, and then navigate to the Resources tab under Related Links.

    2. Click New.

      Retrieve the payload from the request, and then write it to a hybrid queue.

    3. On the form, fill in the fields.

FieldDescription
API DefinitionName of the parent API.
ApplicationThe application containing the script record.
NameName of your API REST Resource. For example, ACME chat.
API versionAPI version. For example, v1.This field displays only if you enabled versioning for the REST API.
ActiveOption to make the REST resource active.
HTTP methodHTTP method, such as POST, GET, and so forth.
Relative pathRelative path to the resource.
ScriptScript for the REST resource.
Protection policyThe protection policy for the script.- Read-only: Script is viewable only. - Protected: Users with password permissions can edit the script.
    Example of a scripted REST resource:

    ```
    (function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
        var body = request.body;
        var queryParams = request.queryParams; // incoming content is application/x-www-form-urlencoded in this example    
        // get the provider application sys id. this can be done via a glide query using incoming data such as where the original message is being sent to. or it can be hard-coded such as this example.
        var providerAppId = "a5f8b75b7377001042281188caf6a73a";    
        // the time of receipt is recorded for analytics purposes
        var d = new Date();
        var logTime = d.getTime();    
        // add this message to the VA Server queue for processing
        var queued = sn_cs.VASystemObject.enqueueCustomAdapterMessage(providerAppId, JSON.stringify(queryParams), JSON.stringify(request.headers), logTime);
        if (queued == false) {
        response.setError(new sn_ws_err.BadRequestError('Failed to process the request.'));
        }
    })(request, response);
    ​

    ```
  1. Set security and content negotiation for your scripted REST resource.

    Choose to set authentication and request formats. If your custom integration does not rely on authentication, you may want to remove it as follows.

    1. In the new record for the Scripted REST Resource, navigate to the Security tab.

    2. Clear Requires authentication.

    3. Click the Content Negotiation tab, and then select Override supported request formats.

    4. Click Submit.

  2. Set REST API rate limits to define the rate of incoming requests.

    1. Navigate to All > System web services > REST > Rate Limit Rules.

    2. Click New.

    3. On the form, fill in the fields.

FieldDescription
NameUnique name for the rate limit rule.
REST APIREST API that you created in an earlier step.
VersionVersion of the REST API. Values listed depend on the selected REST API.
ResourceResource for the specified Version. Values listed depend on the selected Version.
ActiveCheck box to indicate that the rate limit rule is active.Rate limit rules are activated by default as soon as you create them. You can deactivate rate limit rules to stop enforcing a rate limit or activate rate limit rules to resume enforcing a rate limit.
Request limit per hourMaximum number of requests allowed per hour.Note: Whenever you update the value of this field, the ServiceNow AI Platform resets the count of requests to 0 and deletes all violations for the current hour.
Apply toUsers restricted by this rule. Select All users.
4.  Click **Submit**.

What to do next

Create the action scripts for your custom chat integration

Parent Topic:Create a Virtual Agent conversational custom chat integration