> For the complete documentation index, see [llms.txt](https://docs.sharelogic.com/unifi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sharelogic.com/unifi/2.2/scripting/snippets.md).

# Snippets

## Scripted SOAP Service

Use this script to add a SOAP endpoint to a Unifi Process. You will need to update the api\_name to be the same as the one you set in the Process record.

```javascript
(function scriptedWebServiceOperation(request, response) {

  var helper = new x_snd_eb.SoapHelper('api_name'); // the API name of the Unifi Process
  var xml = helper.processRequest(soapRequestXML);
  response.soapResponseElement = snd_eb_util.getSoapResponseElement(xml);

})(request, response);
```

## Scripted REST API

Use this script to add a REST endpoint to a Unifi Process. You will need to update the api\_name to be the same as the one you set in the Process record.

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

    x_snd_eb.ws_console.execute('Request received', function() {
        var helper = new x_snd_eb.RestHelper('incident_guide'); // the API name of the Unifi Process
        processAttachment(helper.getRequest().getRecord());
        helper.processRequest(request, response, 'POST'); // the HTTP method of the resource
    });

})(request, response);
```

{% hint style="info" %}
By wrapping the code in console, we give context to Activity Log and prevent multiple database updates.
{% endhint %}

## Poll Requests

### Bond location and data

This script shows how to find a bond based on an external reference and store some data.

```javascript
var integration = poll_request.$model.getIntegration();
var bond = new Bond(integration.getConfig());
var external_ref = 'BP-41951';

try {
  if (bond.locateReference(integration, '', external_ref, 'external')) {
    // found bond ... do your processing here

    bond.setData('key', 'abc');
    bond.setDataObject('key', {foo: 'bar'});

  } else {
    throw 'Unable to locate bond for reference "' + external_ref + '"';
  }
} catch (e) {
  log.error(e);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sharelogic.com/unifi/2.2/scripting/snippets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
