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.
    4. Click Submit.
    5. (Optional) Open the new record, navigate to Related Links and click Enable Versioning, and then click OK.
      Click Update to save your changes.
  2. 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.
      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);
      ​
  3. 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.
  4. 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.
    4. Click Submit.

What to do next

Create the action scripts for your custom chat integration