DigitalTwinsClient.UpdateAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Updates a digital twin.
public virtual System.Threading.Tasks.Task<Microsoft.Azure.Devices.DigitalTwinUpdateResponse> UpdateAsync (string digitalTwinId, string jsonPatch, Microsoft.Azure.Devices.UpdateDigitalTwinOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member UpdateAsync : string * string * Microsoft.Azure.Devices.UpdateDigitalTwinOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.DigitalTwinUpdateResponse>
override this.UpdateAsync : string * string * Microsoft.Azure.Devices.UpdateDigitalTwinOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.DigitalTwinUpdateResponse>
Public Overridable Function UpdateAsync (digitalTwinId As String, jsonPatch As String, Optional requestOptions As UpdateDigitalTwinOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of DigitalTwinUpdateResponse)
Parameters
- digitalTwinId
- String
The Id of the digital twin.
- jsonPatch
- String
The application/json-patch+json operations to be performed on the specified digital twin. This patch can be constructed using JsonPatchDocument. See the example code for more details.
- requestOptions
- UpdateDigitalTwinOptions
The optional settings for this request.
- cancellationToken
- CancellationToken
The cancellationToken.
Returns
The new ETag for the digital twin and the URI location of the digital twin.
Exceptions
When the provided digitalTwinId
or jsonPatch
is null.
When the provided digitalTwinId
or jsonPatch
is empty or whitespace.
Thrown if IoT hub responded to the request with a non-successful status code. For example, if the provided request was throttled, IotHubServiceException with ThrottlingException is thrown. For a complete list of possible error cases, see IotHubServiceErrorCode.
If the HTTP request fails due to an underlying issue such as network connectivity, DNS failure, or server certificate validation.
If the provided cancellationToken
has requested cancellation.
Examples
string propertyName = "targetTemperature"; int propertyValue = 12; var propertyValues = new Dictionary<string, object> { { propertyName, propertyValue } }; var patchDocument = new JsonPatchDocument(); patchDocument.AppendAdd("/myComponentName", propertyValues); string jsonPatch = patchDocument.ToString(); DigitalTwinUpdateResponse updateResponse = await serviceClient.DigitalTwins.UpdateAsync(deviceId, jsonPatch);
Remarks
For further information on how to create the json-patch, see https://docs.microsoft.com/azure/iot-pnp/howto-manage-digital-twin.