> For the complete documentation index, see [llms.txt](https://help.imotions.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.imotions.com/lab/sensor-setup/api/imotions-api-overview.md).

# iMotions API overview

Understand what an API is, which APIs iMotions Lab offers and what you can use them for, such as sending markers, streaming live data and automating studies.

iMotions Lab can exchange data and commands with other software and hardware through its API. This article explains what an API is, describes the APIs in iMotions Lab and what they are used for, and shows how the communication works. For setup and message formats, see [iMotions Lab API](https://help.imotions.com/lab/sensor-setup/api/imotions-lab-api.md).

## What an API is

An *API* (application programming interface) is an agreed way for two programs to talk to each other. Instead of a person clicking buttons in iMotions, another program sends iMotions messages in a fixed format, and iMotions acts on them or sends messages back.

With the iMotions API, your own software or a third-party system can, for example, send event markers to iMotions while a respondent is recorded, receive the respondent's eye tracking data as it is collected, or start a recording without anyone touching iMotions. The program on the other side can be anything that can send and receive network messages: an experiment built in PsychoPy, a driving simulator, a game, a script in Python or MATLAB, or a hardware device.

## The APIs in iMotions Lab

iMotions Lab has four APIs.

| API                     | What it does                                                                                                                                               | Typical uses                                                                                                                 |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Event Receiving         | Another program sends sensor data and event markers to iMotions, which records them with the rest of the data.                                             | Marking trials, responses or game events on the timeline; recording a sensor that iMotions has no built-in support for.      |
| Event Forwarding        | iMotions sends the data it collects, such as eye tracking, facial expression, GSR or EEG data, to another program while it records.                        | Biofeedback, stimuli that react to the respondent, gaze-controlled interfaces.                                               |
| Replay Event Forwarding | iMotions sends the recorded data to another program again when you replay a recording.                                                                     | Testing a program that uses forwarded data without recording new respondents.                                                |
| Remote Control          | Another program sends commands to iMotions, such as starting a recording, moving to the next stimulus or exporting data, and gets a reply to each command. | Running studies from a simulator or experiment program, automating data collection on several computers, automating exports. |

For example, in a driving simulator study, the simulator software can start the iMotions recording with the Remote Control API, send a marker each time a hazard appears with the Event Receiving API, and adjust the scenario to the driver's gaze with data from the Event Forwarding API.

## How the communication works

iMotions and the other program exchange short text messages over a network connection, using either TCP or UDP. Each API uses its own network port, a number that identifies the connection on the computer. The other program can run on the same computer as iMotions or on another computer on the network.

![iMotions and the external software or hardware send and listen for messages through a UDP or TCP port](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-6314f0733dc65aa434f010fb61f650b92af287df%2F685ac9be2a_image-1674046600450.webp?alt=media)

Depending on the API, one side sends messages to the port and the other listens on it:

* With the Event Receiving and Remote Control APIs, iMotions listens and your program sends. With Remote Control, iMotions also replies to each command.
* With the Event Forwarding APIs, iMotions sends and your program listens.

Each message is one line of text with fields separated by semicolons. The first fields say what kind of message it is, for example `R` for a Remote Control command or `M` for a marker, and every message ends with a carriage return and line feed (`\r\n`). Forwarded data can also be sent as JSON instead.

![Examples of a Remote Control STATUS command and an event marker, with fields separated by semicolons and ending with \r\n](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-b1adaf7bdc44c0bf1703d8f3456dbb96b89ce65c%2F83c69bc4b2_image-1674046692413.webp?alt=media)

## Getting started

1. Enable the APIs you need on the **API** tab of Global Settings and note their ports.

   ![API tab of Global Settings with Remote Control, Event Forwarding, Replay Event Forwarding and Event Receiving](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-bc68bc47f539bda9458011fc086ed05d6984da8a%2Fd96d025d37_image-1731433845273.webp?alt=media)
2. For the Event Receiving API, include the **External Events API** sensor in your study.
3. Write or configure the other program to send or read messages in the iMotions format.

[iMotions Lab API](https://help.imotions.com/lab/sensor-setup/api/imotions-lab-api.md) describes each setting, the message formats and the Remote Control commands. The [iMotions API examples on GitHub](https://github.com/imotions/iMotions-ApiExamples) contain working code in Python, PsychoPy and TypeScript.

To check that data arrives, look at the **Incoming Events API** sensor widget at the bottom of the main iMotions window. It shows **Collecting** while sensor data is received and shows the name of each marker as it arrives. The received data and markers also appear in the [Sensor Preview](https://help.imotions.com/lab/data-collection/sensor-preview-window.md) and in the replay of the recording.

![Incoming Events API widget showing Collecting, and the replay with API event markers and received signals](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-9cf781db7979b99f89ac5a7270724b3de40a07fd%2Fb50055cdd7_image-1727384469642.webp?alt=media)

To check forwarded data without writing a program, you can use a network tool such as PuTTY; see [Event Forwarding API example (streaming to external software)](https://help.imotions.com/lab/sensor-setup/api/event-forwarding-api-example-streaming-to-external-software.md).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.imotions.com/lab/sensor-setup/api/imotions-api-overview.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
