> For the complete documentation index, see [llms.txt](https://developer.singular.live/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.singular.live/data-stream-api/how-to-guides/link-a-data-stream-to-a-composition.md).

# Link a data stream to a composition

{% hint style="info" %}
This how-to guide requires composition scripting to prepare the composition to accept data from the data stream API. For an overview of composition scripting and to learn how to accomplish common tasks with it, visit the [composition scripting](/composition-scripting/introduction.md) section of this portal.&#x20;
{% endhint %}

1. Open the composition you want to connect to a data stream in Composer.
2. If you haven't already created a control node for the widget you want to update with the data stream API, [create a control node](/singular-basics/building-overlays-in-composer/how-to-set-up-control-nodes-to-make-widget-properties-available-to-a-control-app.md) for it.
3. Open the [composition script editor](/singular-basics/building-overlays-in-composer/composer-reference.md#areas-of-the-property-panel) and paste this code snippet into it. You'll need to connect it to the control node in strep 2 and also add the public data stream token.

{% code title="Composition Script" %}

```javascript
context.utils.createDataStream(
  data_stream_public_token, 
  (status, payload) => 
  {
    console.log("we have received: ", status, payload);
    if (status === "message") {
      	// process your data here
    }
  });
```

{% endcode %}

{% hint style="info" %}
For more help, see the composition scripting section of this portal.
{% endhint %}


---

# 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://developer.singular.live/data-stream-api/how-to-guides/link-a-data-stream-to-a-composition.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.
