# Changing a preset

A couple of steps are needed to perform a preset change in our system.

* Getting a list of spaces and presets
* Patching a selected space with the desired preset

That data can be fetched from the interactive API or other HTTP request methods.

#### Getting a list of spaces <a href="#getting-a-list-of-spaces" id="getting-a-list-of-spaces"></a>

This is done through the `GET /spaces` method. Here is a sample data output. You can try it out yourself.

```json
{
  "1ca6407b-05f7-4bee-ac93-ec8c19879749": {
    "name": "Conference breakout",
    "presets": {
      "023c3d35-5d5c-4def-aea2-3ae07c88ddae": {
        "name": "Preset 1 for Conference breakout"
      },
      "75258a79-f949-44e2-b248-519665a404f2": {
        "name": "Preset 2 for Conference breakout"
      }
    },
    "active_preset_id": "023c3d35-5d5c-4def-aea2-3ae07c88ddae",
    "active_environmental_conditions_id": null
  },
  "1d32edb0-4a56-4571-a6c5-49050ca06d51": {
    "name": "Main Hall",
    "presets": {
      "23d6cd0e-5b53-460b-9202-b152538850c0": {
        "name": "Preset 2 for Main Hall"
      },
      "51fa103c-44bb-4ccd-96f7-4c0c2d90c34f": {
        "name": "Preset 3 for Main Hall"
      },
      "9d2514db-0cf6-4cdf-86fc-362f16e3e6d7": {
        "name": "Preset 1 for Main Hall"
      }
    },
    "active_preset_id": "23d6cd0e-5b53-460b-9202-b152538850c0",
    "active_environmental_conditions_id": null,
    "environmental_conditions": {
      "temperature_celsius": 20,
      "atmospheric_pressure_pascal": 101325,
      "humidity_percentage": 50
    }
  },
  "e37c777e-a4b4-4edb-b9dc-d28a497517cf": {
    "name": "Food court",
    "presets": {
      "daa1d51e-9e16-47d7-b142-d6e921acf9bc": {
        "name": "Preset 1 for Food court"
      }
    },
    "active_preset_id": null,
    "active_environmental_conditions_id": null
  }
}
```

In the response above, you can already see the list of available spaces (“Conference breakout,” “Main Hall,” and “Food Court”) and their respective presets. Each space and Preset is referenced by a unique identifier (UUID).

For this example, let’s examine the “Main Hall”. Its ID is `1d32edb0-4a56-4571-a6c5-49050ca06d51`.

```json
…
  "1d32edb0-4a56-4571-a6c5-49050ca06d51": {
    "name": "Main Hall",
    "presets": {
      "23d6cd0e-5b53-460b-9202-b152538850c0": {
        "name": "Preset 2 for Main Hall"
      },
      "51fa103c-44bb-4ccd-96f7-4c0c2d90c34f": {
        "name": "Preset 3 for Main Hall"
      },
      "9d2514db-0cf6-4cdf-86fc-362f16e3e6d7": {
        "name": "Preset 1 for Main Hall"
      }
    },
    "active_preset_id": "23d6cd0e-5b53-460b-9202-b152538850c0",
    "active_environmental_conditions_id": null,
    "environmental_conditions": {
      "temperature_celsius": 20,
      "atmospheric_pressure_pascal": 101325,
      "humidity_percentage": 50
    }
  },
…
```

It has three available presets, and the currently active preset is `Preset 2 for Main Hall`.

#### Changing the active preset <a href="#changing-the-active-preset" id="changing-the-active-preset"></a>

We will use the `PATCH /spaces/{space-id}` method for this operation. We will change the active preset to `Preset 1 for Main Hall`. The method takes a request body with the following format:

```json
{
  "active_preset_id": "51fa103c-44bb-4ccd-96f7-4c0c2d90c34f"
}
```

#### Using cURL <a href="#using-curl" id="using-curl"></a>

cURL is a program available on Windows 10 and above, MacOS, and Linux OS. It provides a simple way to interact with HTTP endpoints and test API requests. Whenever you use one of the API Methods in the interactive documentation, it will display the corresponding request as a cURL command. This makes it easy to copy, paste, and iterate the request.

```bash
curl -X 'PATCH' \
  'http://localhost:6789/spaces/1d32edb0-4a56-4571-a6c5-49050ca06d51' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "active_preset_id": "51fa103c-44bb-4ccd-96f7-4c0c2d90c34f"
}'
```

You should expect a response with the confirmed patched space when you send that.

<div align="center"><figure><img src="/files/EkTJJ9tamsinjdG70ad8" alt=""><figcaption><p>Request</p></figcaption></figure></div>

<div align="right"><figure><img src="/files/qV1gkvryOZOx3nTpqpND" alt=""><figcaption><p>Additional information in the API Application</p></figcaption></figure></div>

#### Using QLab <a href="#using-qlab" id="using-qlab"></a>

You need to create a Script Cue and include the following code. The script is simply an AppleScript version of the cURL command.

```applescript
do shell script "curl -X 'PATCH' 'http://localhost:6789/spaces/1d32edb0-4a56-4571-a6c5-49050ca06d51' -H 'accept: application/json'  -H 'Content-Type: application/json' -d '{
\"active_preset_id\": \"23d6cd0e-5b53-460b-9202-b152538850c0\" }'"
```

<figure><img src="/files/QRbDXMWsLSMIwgrZVyOt" alt=""><figcaption><p>Changing the preset</p></figcaption></figure>


---

# 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.holoplot.com/holoplot-api/examples/changing-a-preset.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.
