CreateThing
Creates a new Thing with ID org.eclipse.ditto:fancy-thing_53
that uses an existing Policy with ID org.eclipse.ditto:the_policy_id
.
{
"topic": "org.eclipse.ditto/fancy-thing/things/twin/commands/create",
"headers": {
"correlation-id": "<command-correlation-id>"
},
"path": "/",
"value": {
"thingId": "org.eclipse.ditto:fancy-thing_53",
"policyId": "org.eclipse.ditto:the_policy_id",
"definition": "org.eclipse.ditto:SomeModel:1.0.0",
"attributes": {
"location": {
"latitude": 44.673856,
"longitude": 8.261719
}
},
"features": {
"accelerometer": {
"properties": {
"x": 3.141,
"y": 2.718,
"z": 1,
"unit": "g"
},
"desiredProperties": {
"x": 4
}
}
}
}
}
CreateThingResponse
{
"topic": "org.eclipse.ditto/fancy-thing/things/twin/commands/create",
"headers": {
"correlation-id": "<preserved-command-correlation-id>"
},
"path": "/",
"value": {
"thingId": "org.eclipse.ditto:fancy-thing_53",
"policyId": "org.eclipse.ditto:the_policy_id",
"definition": "org.eclipse.ditto:SomeModel:1.0.0",
"attributes": {
"location": {
"latitude": 44.673856,
"longitude": 8.261719
}
},
"features": {
"accelerometer": {
"properties": {
"x": 3.141,
"y": 2.718,
"z": 1,
"unit": "g"
},
"desiredProperties": {
"x": 4
}
}
}
},
"status": 201
}
ThingCreated
{
"topic": "org.eclipse.ditto/fancy-thing/things/twin/events/created",
"headers": {
"correlation-id": "<preserved-command-correlation-id>"
},
"path": "/",
"value": {
"thingId": "org.eclipse.ditto:fancy-thing_53",
"policyId": "org.eclipse.ditto:the_policy_id",
"attributes": {
"location": {
"latitude": 44.673856,
"longitude": 8.261719
}
},
"features": {
"accelerometer": {
"properties": {
"x": 3.141,
"y": 2.718,
"z": 1,
"unit": "g"
},
"desiredProperties": {
"x": 4,
"y": 3,
"z": 5,
"unit": "g"
}
}
}
},
"revision": 1
}
Alternative CreateThing commands
If you want to copy an existing Policy instead of creating a new one by yourself or reference an existing Policy, you can adjust the CreateThing command like demonstrated in the following examples.
CreateThing with copied Policy by Policy ID
Creates a new Thing with ID org.eclipse.ditto:fancy-thing_53
with a Policy copied from the Policy with ID org.eclipse.ditto:the_policy_id_to_copy
.
{
"topic": "org.eclipse.ditto/fancy-thing/things/twin/commands/create",
"headers": {
"correlation-id": "<command-correlation-id>"
},
"path": "/",
"value": {
"thingId": "org.eclipse.ditto:fancy-thing_53",
"policyId": "org.eclipse.ditto:the_policy_id",
"_copyPolicyFrom": "com:acme:the_policy_id_to_copy"
}
}
CreateThing with copied Policy by Thing reference
Creates a new Thing with ID org.eclipse.ditto:fancy-thing_53
with a Policy copied from a Thing with ID org.eclipse.ditto:fancy-thing_52
.
{
"topic": "org.eclipse.ditto/fancy-thing/things/twin/commands/create",
"headers": {
"correlation-id": "<command-correlation-id>"
},
"path": "/",
"value": {
"thingId": "org.eclipse.ditto:fancy-thing_53",
"policyId": "org.eclipse.ditto:the_policy_id",
"_copyPolicyFrom": "{{ ref:things/com:acme:fancy-thing_52/policyId }}"
}
}