> For the complete documentation index, see [llms.txt](https://docs.cybus.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cybus.io/2-8-0/data-flows/services/managing/changing-resources-through-the-api.md). Agents can also search and read this documentation through its [MCP server](https://docs.cybus.io/~gitbook/mcp).

# Changing Resources Through the API

Create, change, rename, and delete single connections, endpoints, and mappings through the HTTP API, without sending a whole service commissioning file.

With the [Services API](https://docs.cybus.io/2-8-0/reference/api-reference/services-api.md), you can read and write one resource of a service as JSON. To change an endpoint, you send that endpoint, not the whole service commissioning file.

Connectware writes your change into the stored service commissioning file and deploys it as a service update. A write that a service update would refuse changes nothing. Comments and all other lines of the service commissioning file stay as they are.

## Before You Start

* **Resource types**: You can write `Cybus::Connection`, `Cybus::Endpoint`, and `Cybus::Mapping`, as well as the [Unified Namespace](https://docs.cybus.io/2-8-0/unified-namespace/unified-namespace.md) resources `Cybus::Namespace`, `Cybus::Model`, `Cybus::Asset`, and `Cybus::Mount`. The examples on this page use endpoints.
* **Permissions**: The HTTP permission `/api/v2/resources/#` with `write` to write, or `read` to read. The `connectware-admin` role has both, and `minimum-access` has `read`.
* **Authentication**: A bearer token. See [JSON Web Tokens](https://docs.cybus.io/2-8-0/access/security/json-web-tokens.md).

{% hint style="warning" %}
Roles that you copied from `connectware-admin` before you upgraded to Connectware 2.8.0 do not have the write permission. Add it yourself. See [Permissions](https://docs.cybus.io/2-8-0/access/user-management/permissions.md#http-permission-syntax).
{% endhint %}

## Routes

All routes are relative to `https://${CONNECTWARE_HOST}/api` and are part of the Service Manager OpenAPI file:

{% file src="/files/TbeQXlfcfZE7VhWKXl7P" %}

| Method   | Path                               | Action                                |
| -------- | ---------------------------------- | ------------------------------------- |
| `GET`    | `/v2/resources/by-uid/:uid`        | Read a resource.                      |
| `GET`    | `/v2/resources/by-id/:id`          | Read a resource by its ID.            |
| `POST`   | `/v2/resources`                    | Create a resource.                    |
| `PUT`    | `/v2/resources/by-uid/:uid`        | Replace the properties of a resource. |
| `PATCH`  | `/v2/resources/by-uid/:uid`        | Change some properties of a resource. |
| `DELETE` | `/v2/resources/by-uid/:uid`        | Delete a resource.                    |
| `POST`   | `/v2/resources/by-uid/:uid/rename` | Rename a resource inside its service. |

Every resource has a **uid**, a UUID that never changes, and an **ID**, `<serviceId>-<name>`, which changes when you rename the resource. Writes use the uid. If you know only the service ID and the name, read the resource by its ID to get the uid.

## Change a Resource

This example changes the sampling interval of the endpoint `temperature` in the service `machine01`.

{% stepper %}
{% step %}

### Read the Resource

{% code lineNumbers="true" %}

```bash
curl -i "https://${CONNECTWARE_HOST}/api/v2/resources/by-id/machine01-temperature" \
  --header "Authorization: Bearer ${TOKEN}"
```

{% endcode %}

* `${CONNECTWARE_HOST}`: The hostname or IP address of your Connectware installation.
* `${TOKEN}`: Your bearer token.

The `ETag` header holds the revision of the resource. The body holds the resource as written in the service commissioning file, with references and parameters unresolved:

{% code lineNumbers="true" %}

```json
{
  "jsonapi": { "version": "1.1" },
  "data": {
    "uid": "0a106aef-3490-4eac-b6b4-c03af320bb92",
    "id": "machine01-temperature",
    "name": "temperature",
    "type": "Cybus::Endpoint",
    "serviceId": "machine01",
    "properties": {
      "protocol": "Opcua",
      "connection": { "!ref": "opcuaConnection" },
      "subscribe": { "nodeId": "ns=1;s=Temperature", "samplingInterval": 1000 }
    },
    "_sys": {
      "category": "Endpoint",
      "revision": "5b0d1c2e-9a51-4f0e-8f6e-2f3c1f7d9a10",
      "service": { "targetState": "enabled" },
      "effective": {
        "runnerName": "protocol-mapper",
        "topics": ["services/machine01/temperature"]
      },
      "createdAt": "2026-10-05T08:00:00.000Z",
      "updatedAt": "2026-10-05T08:00:00.000Z"
    }
  },
  "meta": {}
}
```

{% endcode %}

For the fields, see [Resource Fields](#resource-fields).
{% endstep %}

{% step %}

### Send the Change

Send the uid in the path and the revision in `If-Match`:

{% code lineNumbers="true" %}

```bash
curl -X PATCH "https://${CONNECTWARE_HOST}/api/v2/resources/by-uid/${UID}" \
  --header "Authorization: Bearer ${TOKEN}" \
  --header "Content-Type: application/merge-patch+json" \
  --header "If-Match: ${REVISION}" \
  --data '{ "properties": { "subscribe": { "samplingInterval": 500 } } }'
```

{% endcode %}

* `${UID}`: The value of `data.uid`.
* `${REVISION}`: The value of the `ETag` header.

`PATCH` is a JSON merge patch: it changes only the properties you send, and `null` removes a property. A list is replaced as a whole, so send the complete list. `application/json` also works as the content type.

Every write except a create needs `If-Match`: `PUT`, `PATCH`, `DELETE`, and rename.

To check a write first without storing or deploying it, add `?dryRun=true` to the URL. This works for every write.
{% endstep %}

{% step %}

### Check the Response

The response holds the resource after the write, the new revision in the `ETag` header, and a `meta` block. See [Write Response](#write-response).

If the response is `412`, another client changed the resource since your read. Read it again and repeat your change.
{% endstep %}
{% endstepper %}

## Other Writes

### Create a Resource

{% code lineNumbers="true" %}

```bash
curl -X POST "https://${CONNECTWARE_HOST}/api/v2/resources" \
  --header "Authorization: Bearer ${TOKEN}" \
  --header "Content-Type: application/json" \
  --data '{
    "serviceId": "machine01",
    "type": "Cybus::Endpoint",
    "name": "pressure",
    "properties": {
      "protocol": "Opcua",
      "connection": { "!ref": "opcuaConnection" },
      "subscribe": { "nodeId": "ns=1;s=Pressure", "samplingInterval": 1000 }
    }
  }'
```

{% endcode %}

| Field        | Required | Description                                                                                                                |
| ------------ | -------- | -------------------------------------------------------------------------------------------------------------------------- |
| `serviceId`  | no       | The service that gets the resource. Without it, the resource goes into the [workspace service](#workspace-service).        |
| `type`       | yes      | The resource type, such as `Cybus::Endpoint`.                                                                              |
| `name`       | yes      | The key of the resource in the service commissioning file. Letters, digits, `_`, and `.`, starting with a letter or digit. |
| `properties` | yes      | The properties of the resource. Connectware checks them against the schema of the type.                                    |

A create needs no `If-Match` and returns `201`, with the address of the new resource in the `Location` header.

### Replace All Properties

`PUT` replaces the whole `properties` block. You can send back the body of a read: `_sys` is ignored, and `uid`, `id`, `serviceId`, `name`, and `type` must match the resource if you send them. A write cannot move a resource to another service or change its type.

### Turn a Resource On or Off

Set `targetState` to `disconnected` for a connection, or `disabled` for an endpoint or a mapping:

{% code lineNumbers="true" %}

```json
{ "properties": { "targetState": "disabled" } }
```

{% endcode %}

* A connection cannot be turned off while its endpoints, or mappings that use it, are still on. The write returns `422`, and `meta.dependents` lists them. Turn those off first.
* A `PUT` without `targetState` turns the resource on again.

### Delete a Resource

A resource cannot be deleted while other resources reference it, in any service. The delete returns `422`, and `meta.dependents` lists them. Delete those first. Connectware never deletes them for you.

### Rename a Resource

{% code lineNumbers="true" %}

```bash
curl -X POST "https://${CONNECTWARE_HOST}/api/v2/resources/by-uid/${UID}/rename" \
  --header "Authorization: Bearer ${TOKEN}" \
  --header "Content-Type: application/json" \
  --header "If-Match: ${REVISION}" \
  --data '{ "to": "shopFloorBroker" }'
```

{% endcode %}

A rename keeps the uid and changes the ID and the MQTT topics that contain the name, such as `services/<serviceId>/<name>`. Renaming in the service commissioning file instead gives the resource a new uid.

Connectware updates the references to the resource in one step. If one service refuses the change, nothing changes.

| Reference                                                                   | Result                                                                                                                    |
| --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `!ref oldName` or `${oldName}` in the same service commissioning file       | Rewritten.                                                                                                                |
| `!ref '${parentServiceId}::oldName'` in another service                     | Rewritten. See [Inter-Service Referencing](https://docs.cybus.io/2-8-0/data-flows/services/inter-service-referencing.md). |
| The ID as plain text, such as `connection: machine01-plc`                   | Not a reference. Left as it is.                                                                                           |
| A name built from a parameter, such as `!ref '${parentServiceId}::${name}'` | Rename refused.                                                                                                           |
| `${serviceId::name}` with the service ID written out                        | Rename refused.                                                                                                           |

A rename is also refused in the following cases:

* The old or the new name is `mqttConnection`.
* An enabled service references the resource and another resource whose topic the rename moves. Disable that service first.
* The resource is a namespace, model, asset, or mount, and resources of other services depend on it. They name it by its root, its model ID, or its ID, which a rename cannot rewrite.
* The resource is an asset, and a resource of its own service names it as plain text, such as `asset: pump01.temperature`. A `!ref` to the asset is rewritten.

## Resource Fields

| Field                       | Description                                                                                                                                                                                          |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `properties`                | The block as written in the service commissioning file. See [Writing Properties](https://docs.cybus.io/2-8-0/data-flows/services/managing/changing-resources-through-the-api/writing-properties.md). |
| `_sys`                      | Read-only. A write ignores it.                                                                                                                                                                       |
| `_sys.revision`             | The revision to send in `If-Match`. Also in the `ETag` header.                                                                                                                                       |
| `_sys.service.targetState`  | The target state of the service. The resource's own target state is `properties.targetState`.                                                                                                        |
| `_sys.effective.runnerName` | The agent that runs the resource, or `null`. An endpoint runs where its connection runs.                                                                                                             |
| `_sys.effective.topics`     | The MQTT topics of the resource.                                                                                                                                                                     |

The route `GET /v2/resources/:resourceId` still returns the resource as deployed, with references and parameters resolved.

## Write Response

| Field                 | Description                                                                                                                           |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `revision`            | The revision after the write, also in the `ETag` header. `null` for a dry run of a create.                                            |
| `dryRun`              | Whether the write was a dry run.                                                                                                      |
| `reprovisioned`       | Whether Connectware deployed the write, or would deploy it in a dry run.                                                              |
| `reapplied`           | The resources that Connectware deployed again. Not in a dry run.                                                                      |
| `dependents`          | On a `422`, the resources that block the write, as `[{ id, type, serviceId }]`. With `id` and `type` set to `null`, only the service. |
| `renamed`             | For a rename, the old and the new ID.                                                                                                 |
| `rewrittenDependents` | For a rename, the resources in other services whose references changed.                                                               |
| `topicsRenamed`       | For a rename that moved topics, the topics before (`from`) and after (`to`). The lists are sorted separately, so do not pair them.    |
| `warnings`            | Warnings about the write, for example a service that could not be enabled again.                                                      |

A delete returns the resource as it was before the delete. A dry run of a create returns no `uid`, and `_sys.effective` is `null`.

## What a Write Deploys

| Service                                              | Result                                                                                                  |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| Enabled                                              | Connectware deploys the changed resource and the resources that depend on it. The others keep running.  |
| Disabled                                             | Connectware stores the change and deploys nothing.                                                      |
| Disabled by a parent service                         | Connectware enables the service again once every parent is enabled. If that fails, `warnings` says why. |
| A child service that references the changed resource | Restarts only if the change affects it, for example a new topic of an endpoint.                         |

{% hint style="info" %}
If `mqttConnection` uses `password: !ref Cybus::MqttPassword`, every write to the service generates a new MQTT password, as a service update does. Connectware then deploys `mqttConnection` and the users with that password again.
{% endhint %}

## Workspace Service

A create without `serviceId` puts the resource into the workspace service, `cybus_workspace`. Connectware installs it, enabled, the first time you need it. After that, you manage it like any other service. If you delete it, the next create without `serviceId` installs it again, after the [reinstall delay](https://docs.cybus.io/2-8-0/data-flows/services/managing/deleting.md).

| Situation                                                                      | Result                                                                                                                                                 |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| You install a new service with the workspace ID.                               | The installation returns `406`.                                                                                                                        |
| A service you installed before Connectware 2.8.0 already has the workspace ID. | A create without `serviceId` returns `409`. Name the service in `serviceId`, or [change the workspace service ID](#changing-the-workspace-service-id). |
| You change `CYBUS_WORKSPACE_SERVICE_ID` later.                                 | The old workspace service stays as a regular service.                                                                                                  |

Connectware recognizes the workspace service by `metadata.provider: Cybus Connectware resource write API` in its service commissioning file. Do not change this value.

### Changing the Workspace Service ID

To use another ID for the workspace service, set the `CYBUS_WORKSPACE_SERVICE_ID` environment variable of the Service Manager. The ID can contain letters, digits, `_`, and `.`, and must start with a letter or digit. With an invalid ID, such as `my-workspace`, the Service Manager does not start.

{% tabs %}
{% tab title="Kubernetes" %}
In your `values.yaml` file, add the variable to `serviceManager.env`, which sets environment variables for the Service Manager:

{% code lineNumbers="true" %}

```yaml
serviceManager:
  env:
    - name: CYBUS_WORKSPACE_SERVICE_ID
      value: 'my_workspace'
```

{% endcode %}

Apply the change with a Helm upgrade. See [Applying Helm Configuration Changes](https://docs.cybus.io/2-8-0/cybus-helm-charts/working-with-cybus-helm-charts.md#applying-helm-configuration-changes).
{% endtab %}

{% tab title="Docker" %}
In the `docker-compose.override.yml` file in your Connectware installation directory, add the variable to the `service-manager` service:

{% code lineNumbers="true" %}

```yaml
services:
  service-manager:
    environment:
      CYBUS_WORKSPACE_SERVICE_ID: 'my_workspace'
```

{% endcode %}

To apply the change, run `docker compose up -d` in the installation directory.
{% endtab %}
{% endtabs %}

## Status Codes

Errors use the JSON:API `errors` array, with `status`, `title`, and `detail`.

| Status | Meaning                                                                                                                      |
| ------ | ---------------------------------------------------------------------------------------------------------------------------- |
| `200`  | Success, including any dry run.                                                                                              |
| `201`  | Created.                                                                                                                     |
| `400`  | Malformed request, for example an unknown type, a uid that is not a UUID, or properties that do not match the schema.        |
| `404`  | No resource with this uid or ID, or no service with this `serviceId`.                                                        |
| `405`  | The type can be read but not written. `meta.writableTypes` lists the writable types.                                         |
| `409`  | The name is already used in the service, or a service you installed holds the workspace ID.                                  |
| `412`  | The resource changed since your read.                                                                                        |
| `422`  | The service update would fail, with the reason in `detail`, or other resources block the write, listed in `meta.dependents`. |
| `423`  | The service, or a service the write affects, is busy. Retry after the seconds in the `Retry-After` header.                   |
| `428`  | The `If-Match` header is missing. To skip the revision check, send `If-Match: *`.                                            |

The Service Manager log records each write with the operation, the service, and the resource, but not the user.


---

# 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://docs.cybus.io/2-8-0/data-flows/services/managing/changing-resources-through-the-api.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.
