# Integration Main Module

## &#x20;Directory Structure

```
sample-integration/
└── integration.js
```

## Summary

The `integration.js` file is the entry point into your integration on the server.  The file runs on the server and is responsible for taking entities from the Polarity client, enriching or transforming them, and returning results back to the Polarity client.

{% hint style="info" %}
The `integration.js` file runs in its own process on the Polarity Server so if your integration crashes it will not also crash the server.
{% endhint %}

At a minimum your main module must export a `doLookup` method but it can also provide a `startup`, `validateOptions`, `onDetails`, and `onMessage` method. Each of these methods must be exported from your main module so that they are accessible to the Polarity Server's integration loader.

The minimum `integration.js` file which will properly load is as follows:

{% code title="integration.js" %}

```
function doLookup(entities, options, cb){
    cb(null, []);
}

module.exports = {
    doLookup: doLookup
}
```

{% endcode %}

## Method Hooks

The following table provides a summary of the special methods that can be implemented and exported from the `integration.js` file.

| Method                                                                        | Required     | Description                                                                                                                                   |
| ----------------------------------------------------------------------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
| [startup](/integrations/build-an-integration/main/startup.md)                 | optional     | Executed once when your  integration is started or restarted                                                                                  |
| [doLookup](/integrations/build-an-integration/main/dolookup.md)               | **required** | Enriches or transforms entities passed from the client and returns the enriched data.                                                         |
| [validateOptions](/integrations/build-an-integration/main/validateoptions.md) | optional     | Called anytime a user saves changes to their integration options                                                                              |
| [onDetails](/integrations/build-an-integration/main/ondetails.md)             | optional     | Executed when a user opens the details panel for your integration in the Overlay Window                                                       |
| [onMessage](/integrations/build-an-integration/main/onmessage.md)             | optional     | Used to send messages from your integration's front end code (component and template) to your integration's server side code (integration.js) |


---

# Agent Instructions: 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.polarity.io/integrations/build-an-integration/main.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.
