Twins - DigitalTwins Add

Adds or replaces a digital twin. Status codes:

  • 200 OK
  • 400 Bad Request
    • InvalidArgument - The digital twin id or payload is invalid.
    • ModelDecommissioned - The model for the digital twin is decommissioned.
    • TwinLimitReached - The maximum number of digital twins allowed has been reached.
    • ValidationFailed - The digital twin payload is not valid.
  • 412 Precondition Failed
    • PreconditionFailed - The precondition check (If-Match or If-None-Match) failed.
PUT https://digitaltwins-hostname/digitaltwins/{id}?api-version=2020-10-31

URI Parameters

Name In Required Type Description
id
path True
  • string

The id of the digital twin. The id is unique within the service and case sensitive.

api-version
query True
  • string

The requested API version.

Request Header

Name Required Type Description
If-None-Match
  • string

Only perform the operation if the entity does not already exist.

traceparent
  • string

Identifies the request in a distributed tracing system.

tracestate
  • string

Provides vendor-specific trace identification information and is a companion to traceparent.

Request Body

Name Type Description
twin
  • object

The digital twin instance being added. If provided, the $dtId property is ignored.

Responses

Name Type Description
200 OK
  • object

Success

Headers

  • ETag: string
202 Accepted

Asynchronous Success

Other Status Codes

Default response.

Security

oauth2

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize?resource=0b07f429-9f4b-4714-9392-cc5e8e80c8b0

Examples

Add a digital twin
Add a digital twin (with properties and components)

Add a digital twin

Sample Request

PUT https://digitaltwins-hostname/digitaltwins/myNewTwinId?api-version=2020-10-31
{
  "$metadata": {
    "$model": "dtmi:com:example:interfaces:interfaceName;1"
  }
}

Sample Response

{
  "$dtId": "myNewTwinId",
  "$metadata": {
    "$model": "dtmi:com:example:interfaces:interfaceName;1"
  }
}

Add a digital twin (with properties and components)

Sample Request

PUT https://digitaltwins-hostname/digitaltwins/myNewTwinId?api-version=2020-10-31
If-None-Match: *
{
  "$metadata": {
    "$model": "dtmi:com:example:interfaces:interfaceName;1"
  },
  "property1": 1,
  "property2": {
    "subProperty1": "some value",
    "subProperty2": "some other value"
  },
  "component1": {
    "$metadata": {},
    "componentProperty": "some value"
  }
}

Sample Response

{
  "$dtId": "myNewTwinId",
  "$metadata": {
    "$model": "dtmi:com:example:interfaces:interfaceName;1",
    "property1": {
      "lastUpdateTime": "2020-05-23T21:44:02Z"
    },
    "property2": {
      "lastUpdateTime": "2020-05-23T21:44:02Z"
    }
  },
  "property1": 1,
  "property2": {
    "subProperty1": "some value",
    "subProperty2": "some other value"
  },
  "component1": {
    "$metadata": {
      "componentProperty": {
        "lastUpdateTime": "2020-05-23T21:44:02Z"
      }
    }
  }
}

Definitions

Error

Error definition.

ErrorResponse

Error response.

InnerError

A more specific error description than was provided by the containing error.

Error

Error definition.

Name Type Description
code
  • string

Service specific error code which serves as the substatus for the HTTP error code.

details

Internal error details.

innererror

An object containing more specific information than the current object about the error.

message
  • string

A human-readable representation of the error.

ErrorResponse

Error response.

Name Type Description
error

The error details.

InnerError

A more specific error description than was provided by the containing error.

Name Type Description
code
  • string

A more specific error code than was provided by the containing error.

innererror

An object containing more specific information than the current object about the error.