I
InsightNexus

Class DigitalTwinsClient | Azure SDK for Net

Author

Andrew Henderson

Published Feb 16, 2026

The Digital Twins Service Client contains methods to retrieve digital twin information, like models, components, and relationships.

Inheritance

DigitalTwinsClient

Namespace: Azure.DigitalTwins.Core
Assembly: Azure.DigitalTwins.Core.dll
Syntax
public class DigitalTwinsClient

Constructors

DigitalTwinsClient()

Creates a new instance of the DigitalTwinsClient class, provided for unit testing purposes only.

Declaration
protected DigitalTwinsClient ();

DigitalTwinsClient(Uri, TokenCredential)

Declaration
public DigitalTwinsClient (Uri endpoint, Azure.Core.TokenCredential credential);
Parameters
Uri endpoint

The Azure digital twins service instance URI to connect to.

TokenCredential credential

The TokenCredential implementation which will be used to request for the authentication token.

Examples
 // DefaultAzureCredential supports different authentication mechanisms and determines the appropriate credential type based of the environment it is executing in. // It attempts to use multiple credential types in an order until it finds a working credential. var tokenCredential = new DefaultAzureCredential(); var client = new DigitalTwinsClient( new Uri(adtEndpoint), tokenCredential);
See Also

DigitalTwinsClient(Uri, TokenCredential, DigitalTwinsClientOptions)

Declaration
public DigitalTwinsClient (Uri endpoint, Azure.Core.TokenCredential credential, Azure.DigitalTwins.Core.DigitalTwinsClientOptions options);
Parameters
Uri endpoint

The Azure digital twins service instance URI to connect to.

TokenCredential credential

The TokenCredential implementation which will be used to request for the authentication token.

DigitalTwinsClientOptions options

Options that allow configuration of requests sent to the digital twins service.

Methods

CreateDigitalTwin(String, String, CancellationToken)

Creates a digital twin synchronously.

Declaration
public virtual Azure.Response<string> CreateDigitalTwin (string digitalTwinId, string digitalTwin, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String digitalTwin

The application/json digital twin to create.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions

CreateDigitalTwinAsync(String, String, CancellationToken)

Creates a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<string>> CreateDigitalTwinAsync (string digitalTwinId, string digitalTwin, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String digitalTwin

The application/json digital twin to create.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 var customTwin = new CustomDigitalTwin { Id = customDtId, Metadata = { ModelId = modelId }, Prop1 = "Prop1 val", Prop2 = 987, Component1 = new Component1 { ComponentProp1 = "Component prop1 val", ComponentProp2 = 123, } }; string dt2Payload = JsonSerializer.Serialize(customTwin); await client.CreateDigitalTwinAsync(customDtId, dt2Payload); Console.WriteLine($"Created digital twin '{customDtId}'.");
Exceptions

CreateEventRoute(String, EventRoute, CancellationToken)

Creates an event route synchronously.

Declaration
public virtual Azure.Response CreateEventRoute (string eventRouteId, Azure.DigitalTwins.Core.EventRoute eventRoute, System.Threading.CancellationToken cancellationToken = null);
Parameters
String eventRouteId

The Id of the event route to create.

EventRoute eventRoute

The event route data containing the endpoint and optional filter.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

CreateEventRouteAsync(String, EventRoute, CancellationToken)

Creates an event route asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> CreateEventRouteAsync (string eventRouteId, Azure.DigitalTwins.Core.EventRoute eventRoute, System.Threading.CancellationToken cancellationToken = null);
Parameters
String eventRouteId

The Id of the event route to create.

EventRoute eventRoute

The event route data containing the endpoint and optional filter.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 string eventFilter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'"; var eventRoute = new EventRoute(eventhubEndpointName) { Filter = eventFilter }; await client.CreateEventRouteAsync(_eventRouteId, eventRoute); Console.WriteLine($"Created event route '{_eventRouteId}'.");
Exceptions

CreateModels(IEnumerable<String>, CancellationToken)

Creates one or many models synchronously.

Declaration
public virtual Azure.Response<Azure.DigitalTwins.Core.ModelData[]> CreateModels (System.Collections.Generic.IEnumerable<string> models, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Exceptions
See Also

CreateModelsAsync(IEnumerable<String>, CancellationToken)

Creates one or many models asynchronously.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.DigitalTwins.Core.ModelData[]>> CreateModelsAsync (System.Collections.Generic.IEnumerable<string> models, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Examples
 await client.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload }); Console.WriteLine($"Created models '{componentModelId}' and '{sampleModelId}'.");
Exceptions

CreateRelationship(String, String, String, CancellationToken)

Creates a relationship on a digital twin synchronously.

Declaration
public virtual Azure.Response<string> CreateRelationship (string digitalTwinId, string relationshipId, string relationship, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipId

The Id of the relationship to delete.

String relationship

The application/json relationship to be created.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

CreateRelationshipAsync(String, String, String, CancellationToken)

Creates a relationship on a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<string>> CreateRelationshipAsync (string digitalTwinId, string relationshipId, string relationship, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipId

The Id of the relationship which is being created.

String relationship

The application/json relationship to be created.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 var floorBuildingRelationshipPayload = new CustomRelationship { Id = "floorBuildingRelationshipId", SourceId = "floorTwinId", TargetId = "buildingTwinId", Name = "containedIn", Prop1 = "Prop1 val", Prop2 = 4 }; string serializedCustomRelationship = JsonSerializer.Serialize(floorBuildingRelationshipPayload); Response<string> createCustomRelationshipResponse = await client.CreateRelationshipAsync("floorTwinId", "floorBuildingRelationshipId", serializedCustomRelationship); Console.WriteLine($"Created a digital twin relationship 'floorBuildingRelationshipId' from twin 'floorTwinId' to twin 'buildingTwinId'.");
Exceptions

DecommissionModel(String, CancellationToken)

Decommissions a model synchronously.

Declaration
public virtual Azure.Response DecommissionModel (string modelId, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Exceptions
See Also

DecommissionModelAsync(String, CancellationToken)

Decommissions a model asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> DecommissionModelAsync (string modelId, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Examples
 try { await client.DecommissionModelAsync(sampleModelId); Console.WriteLine($"Decommissioned model '{sampleModelId}'."); } catch (RequestFailedException ex) { FatalError($"Failed to decommision model '{sampleModelId}' due to:\n{ex}"); }
Exceptions

DeleteDigitalTwin(String, RequestOptions, CancellationToken)

Deletes a digital twin synchronously.

Declaration
public virtual Azure.Response DeleteDigitalTwin (string digitalTwinId, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin to delete.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions

DeleteDigitalTwinAsync(String, RequestOptions, CancellationToken)

Deletes a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> DeleteDigitalTwinAsync (string digitalTwinId, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin to delete.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 await client.DeleteDigitalTwinAsync(digitalTwinId); Console.WriteLine($"Deleted digital twin '{digitalTwinId}'.");
Exceptions

DeleteEventRoute(String, CancellationToken)

Deletes an event route synchronously.

Declaration
public virtual Azure.Response DeleteEventRoute (string eventRouteId, System.Threading.CancellationToken cancellationToken = null);
Parameters
String eventRouteId

The Id of the event route to delete.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

DeleteEventRouteAsync(String, CancellationToken)

Deletes an event route asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> DeleteEventRouteAsync (string eventRouteId, System.Threading.CancellationToken cancellationToken = null);
Parameters
String eventRouteId

The Id of the event route to delete.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 await client.DeleteEventRouteAsync(_eventRouteId); Console.WriteLine($"Deleted event route '{_eventRouteId}'.");
Exceptions

DeleteModel(String, CancellationToken)

Deletes a model synchronously.

Declaration
public virtual Azure.Response DeleteModel (string modelId, System.Threading.CancellationToken cancellationToken = null);
Parameters
String modelId

The id for the model. The id is globally unique and case sensitive.

CancellationToken cancellationToken

The cancellation token to use.

Returns
Exceptions
See Also

DeleteModelAsync(String, CancellationToken)

Deletes a model asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> DeleteModelAsync (string modelId, System.Threading.CancellationToken cancellationToken = null);
Parameters
String modelId

The id for the model. The id is globally unique and case sensitive.

CancellationToken cancellationToken

The cancellation token to use.

Returns
Examples
 try { await client.DeleteModelAsync(sampleModelId); Console.WriteLine($"Deleted model '{sampleModelId}'."); } catch (Exception ex) { FatalError($"Failed to delete model '{sampleModelId}' due to:\n{ex}"); }
Exceptions

DeleteRelationship(String, String, RequestOptions, CancellationToken)

Deletes a relationship on a digital twin synchronously.

Declaration
public virtual Azure.Response DeleteRelationship (string digitalTwinId, string relationshipId, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipId

The Id of the relationship to delete.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

DeleteRelationshipAsync(String, String, RequestOptions, CancellationToken)

Deletes a relationship on a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> DeleteRelationshipAsync (string digitalTwinId, string relationshipId, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipId

The Id of the relationship to delete.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
Azure.RequestFailedException

The exception is thrown when digitalTwinId or relationshipId is null. The exception that captures the errors from the service. Check the ErrorCode and Status properties for more details.

GetComponent(String, String, CancellationToken)

Gets a component on a digital twin synchronously.

Declaration
public virtual Azure.Response<string> GetComponent (string digitalTwinId, string componentPath, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String componentPath

The component being retrieved.

CancellationToken cancellationToken

The cancellation token.

Returns
Response<String>

Json string representation of the component corresponding to the provided componentPath and the HTTP response Response<T>.

Exceptions
See Also

GetComponentAsync(String, String, CancellationToken)

Gets a component on a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<string>> GetComponentAsync (string digitalTwinId, string componentPath, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String componentPath

The component being retrieved.

CancellationToken cancellationToken

The cancellation token.

Returns
Task<Response<String>>

Json string representation of the component corresponding to the provided componentPath and the HTTP response Response<T>.

Examples
 await client.GetComponentAsync(basicDtId, SamplesConstants.ComponentPath); Console.WriteLine($"Retrieved component for digital twin '{basicDtId}'.");
Exceptions

GetDigitalTwin(String, CancellationToken)

Gets a digital twin synchronously.

Declaration
public virtual Azure.Response<string> GetDigitalTwin (string digitalTwinId, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Exceptions

GetDigitalTwinAsync(String, CancellationToken)

Gets a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<string>> GetDigitalTwinAsync (string digitalTwinId, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Examples

This sample demonstrates getting and deserializing a digital twin into a custom data type.

 Response<string> getCustomDtResponse = await client.GetDigitalTwinAsync(customDtId); CustomDigitalTwin customDt = JsonSerializer.Deserialize<CustomDigitalTwin>(getCustomDtResponse.Value); Console.WriteLine($"Retrieved and deserialized digital twin {customDt.Id}:\n\t" + $"ETag: {customDt.ETag}\n\t" + $"Prop1: {customDt.Prop1}\n\t" + $"Prop2: {customDt.Prop2}\n\t" + $"ComponentProp1: {customDt.Component1.ComponentProp1}\n\t" + $"ComponentProp2: {customDt.Component1.ComponentProp2}"); 
Exceptions

GetEventRoute(String, CancellationToken)

Gets an event route by Id synchronously.

Declaration
public virtual Azure.Response<Azure.DigitalTwins.Core.EventRoute> GetEventRoute (string eventRouteId, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Exceptions
See Also

GetEventRouteAsync(String, CancellationToken)

Gets an event route by Id asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.DigitalTwins.Core.EventRoute>> GetEventRouteAsync (string eventRouteId, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Exceptions

GetEventRoutes(EventRoutesListOptions, CancellationToken)

. Lists the event routes in a digital twins instance by iterating through a collection synchronously.

Declaration
public virtual Azure.Pageable<Azure.DigitalTwins.Core.EventRoute> GetEventRoutes (Azure.DigitalTwins.Core.EventRoutesListOptions options = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
EventRoutesListOptions options

The options to use when listing the event routes. One can set the maximum number of items to retrieve per request, however the service may return less than requested.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

GetEventRoutesAsync(EventRoutesListOptions, CancellationToken)

. Lists the event routes in a digital twins instance by iterating through a collection asynchronously.

Declaration
public virtual Azure.AsyncPageable<Azure.DigitalTwins.Core.EventRoute> GetEventRoutesAsync (Azure.DigitalTwins.Core.EventRoutesListOptions options = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
EventRoutesListOptions options

The options to use when listing the event routes. One can set the maximum number of items to retrieve per request, however the service may return less than requested.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 AsyncPageable<EventRoute> response = client.GetEventRoutesAsync(); await foreach (EventRoute er in response) { Console.WriteLine($"Event route '{er.Id}', endpoint name '{er.EndpointName}'"); }
Exceptions

GetIncomingRelationships(String, CancellationToken)

Gets all the relationships referencing a digital twin as a target by iterating through a collection synchronously.

Declaration
public virtual Azure.Pageable<Azure.DigitalTwins.Core.IncomingRelationship> GetIncomingRelationships (string digitalTwinId, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the target digital twin.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

GetIncomingRelationshipsAsync(String, CancellationToken)

Gets all the relationships referencing a digital twin as a target by iterating through a collection asynchronously.

Declaration
public virtual Azure.AsyncPageable<Azure.DigitalTwins.Core.IncomingRelationship> GetIncomingRelationshipsAsync (string digitalTwinId, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the target digital twin.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 AsyncPageable<IncomingRelationship> incomingRelationships = client.GetIncomingRelationshipsAsync("buildingTwinId"); await foreach (IncomingRelationship incomingRelationship in incomingRelationships) { Console.WriteLine($"Found an incoming relationship '{incomingRelationship.RelationshipId}' from '{incomingRelationship.SourceId}'."); }
Exceptions

GetModel(String, CancellationToken)

Gets a model, including the model metadata and the model definition synchronously.

Declaration
public virtual Azure.Response<Azure.DigitalTwins.Core.ModelData> GetModel (string modelId, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Exceptions
See Also

GetModelAsync(String, CancellationToken)

Gets a model, including the model metadata and the model definition asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.DigitalTwins.Core.ModelData>> GetModelAsync (string modelId, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Examples
 Response<ModelData> sampleModelResponse = await client.GetModelAsync(sampleModelId); Console.WriteLine($"Retrieved model '{sampleModelResponse.Value.Id}'.");
Exceptions

GetModels(IEnumerable<String>, Boolean, GetModelsOptions, CancellationToken)

Gets the list of models by iterating through a collection synchronously.

Declaration
public virtual Azure.Pageable<Azure.DigitalTwins.Core.ModelData> GetModels (System.Collections.Generic.IEnumerable<string> dependenciesFor = null, bool includeModelDefinition = false, Azure.DigitalTwins.Core.GetModelsOptions options = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
IEnumerable<String> dependenciesFor

The model Ids to have dependencies retrieved.

Boolean includeModelDefinition

Whether to include the model definition in the result. If false, only the model metadata will be returned.

GetModelsOptions options

The options to follow when listing the models. For example, the page size hint can be specified.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

GetModelsAsync(IEnumerable<String>, Boolean, GetModelsOptions, CancellationToken)

Gets the list of models by iterating through a collection asynchronously.

Declaration
public virtual Azure.AsyncPageable<Azure.DigitalTwins.Core.ModelData> GetModelsAsync (System.Collections.Generic.IEnumerable<string> dependenciesFor = null, bool includeModelDefinition = false, Azure.DigitalTwins.Core.GetModelsOptions options = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
IEnumerable<String> dependenciesFor

The model Ids to have dependencies retrieved.

Boolean includeModelDefinition

Whether to include the model definition in the result. If false, only the model metadata will be returned.

GetModelsOptions options

The options to follow when listing the models. For example, the page size hint can be specified.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 AsyncPageable<ModelData> allModels = client.GetModelsAsync(); await foreach (ModelData model in allModels) { Console.WriteLine($"Retrieved model '{model.Id}', " + $"display name '{model.DisplayName["en"]}', " + $"upload time '{model.UploadTime}', " + $"and decommissioned '{model.Decommissioned}'"); }
Exceptions

GetRelationship(String, String, CancellationToken)

Gets a relationship on a digital twin synchronously.

Declaration
public virtual Azure.Response<string> GetRelationship (string digitalTwinId, string relationshipId, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipId

The Id of the relationship to retrieve.

CancellationToken cancellationToken

The cancellation token.

Returns
Response<String>

The application/json relationship corresponding to the provided relationshipId and the http response Response<T>.

Exceptions
See Also

GetRelationshipAsync(String, String, CancellationToken)

Gets a relationship on a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<string>> GetRelationshipAsync (string digitalTwinId, string relationshipId, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipId

The Id of the relationship to retrieve.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples

This sample demonstrates getting and deserializing a digital twin relationship into a custom data type.

Response<string> getCustomRelationshipResponse = await client.GetRelationshipAsync("floorTwinId", "floorBuildingRelationshipId");
CustomRelationship getCustomRelationship = JsonSerializer.Deserialize<CustomRelationship>(getCustomRelationshipResponse.Value);
Console.WriteLine($"Retrieved and deserialized relationship '{getCustomRelationship.Id}' from twin '{getCustomRelationship.SourceId}'.\n\t" + $"Prop1: {getCustomRelationship.Prop1}\n\t" + $"Prop2: {getCustomRelationship.Prop2}");
Exceptions

GetRelationships(String, String, CancellationToken)

Gets all the relationships on a digital twin by iterating through a collection synchronously.

Declaration
public virtual Azure.Pageable<string> GetRelationships (string digitalTwinId, string relationshipName = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipName

The name of a relationship to filter to. If null, all relationships for the digital twin will be returned.

CancellationToken cancellationToken

The cancellation token.

Returns
Pageable<String>

The pageable list Pageable<T> of application/json relationships belonging to the specified digital twin and the http response.

Exceptions
See Also

GetRelationshipsAsync(String, String, CancellationToken)

Gets all the relationships on a digital twin by iterating through a collection asynchronously.

Declaration
public virtual Azure.AsyncPageable<string> GetRelationshipsAsync (string digitalTwinId, string relationshipName = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipName

The name of a relationship to filter to. If null, all relationships for the digital twin will be returned.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples

This sample demonstrates iterating over outgoing relationships and deserializing relationship strings into BasicRelationship objects.

AsyncPageable<string> relationships = client.GetRelationshipsAsync("buildingTwinId");
await foreach (var relationshipJson in relationships)
{ BasicRelationship relationship = JsonSerializer.Deserialize<BasicRelationship>(relationshipJson); Console.WriteLine($"Retrieved relationship '{relationship.Id}' with source {relationship.SourceId}' and " + $"target {relationship.TargetId}.\n\t" + $"Prop1: {relationship.CustomProperties["Prop1"]}\n\t" + $"Prop2: {relationship.CustomProperties["Prop2"]}");
}
Exceptions

PublishComponentTelemetry(String, String, String, TelemetryOptions, CancellationToken)

Publishes telemetry from a digital twin's component synchronously. The result is then consumed by one or many destination endpoints (subscribers) defined under EventRoute. These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.

Declaration
public virtual Azure.Response PublishComponentTelemetry (string digitalTwinId, string componentName, string payload, Azure.DigitalTwins.Core.TelemetryOptions options = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String componentName

The name of the DTDL component.

String payload

The application/json telemetry payload to be sent.

TelemetryOptions options

The additional information to be used when processing a telemetry request.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

PublishComponentTelemetryAsync(String, String, String, TelemetryOptions, CancellationToken)

Publishes telemetry from a digital twin's component asynchronously. The result is then consumed by one or many destination endpoints (subscribers) defined under EventRoute. These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> PublishComponentTelemetryAsync (string digitalTwinId, string componentName, string payload, Azure.DigitalTwins.Core.TelemetryOptions options = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String componentName

The name of the DTDL component.

String payload

The application/json telemetry payload to be sent.

TelemetryOptions options

The additional information to be used when processing a telemetry request.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 // construct your json telemetry payload by serializing a dictionary. var telemetryPayload = new Dictionary<string, int> { { "ComponentTelemetry1", 9 } }; await client.PublishComponentTelemetryAsync( twinId, "Component1", JsonSerializer.Serialize(telemetryPayload)); Console.WriteLine($"Published component telemetry message to twin '{twinId}'.");
Exceptions

PublishTelemetry(String, String, TelemetryOptions, CancellationToken)

Publishes telemetry from a digital twin synchronously. The result is then consumed by one or many destination endpoints (subscribers) defined under EventRoute. These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.

Declaration
public virtual Azure.Response PublishTelemetry (string digitalTwinId, string payload, Azure.DigitalTwins.Core.TelemetryOptions options = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String payload

The application/json telemetry payload to be sent.

TelemetryOptions options

The additional information to be used when processing a telemetry request.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

PublishTelemetryAsync(String, String, TelemetryOptions, CancellationToken)

Publishes telemetry from a digital twin asynchronously. The result is then consumed by one or many destination endpoints (subscribers) defined under EventRoute. These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> PublishTelemetryAsync (string digitalTwinId, string payload, Azure.DigitalTwins.Core.TelemetryOptions options = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String payload

The application/json telemetry payload to be sent.

TelemetryOptions options

The additional information to be used when processing a telemetry request.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
 // construct your json telemetry payload by hand. await client.PublishTelemetryAsync(twinId, "{\"Telemetry1\": 5}"); Console.WriteLine($"Published telemetry message to twin '{twinId}'.");
Exceptions

Query(String, CancellationToken)

Queries for digital twins by iterating through a collection synchronously.

Declaration
public virtual Azure.Pageable<string> Query (string query, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Examples

A basic query for all digital twins: SELECT * FROM digitalTwins.

Exceptions
See Also

QueryAsync(String, CancellationToken)

Queries for digital twins by iterating through a collection asynchronously.

Declaration
public virtual Azure.AsyncPageable<string> QueryAsync (string query, System.Threading.CancellationToken cancellationToken = null);
Parameters
Returns
Examples
 // This code snippet demonstrates the simplest way to iterate over the digital twin results, where paging // happens under the covers. AsyncPageable<string> asyncPageableResponse = client.QueryAsync("SELECT * FROM digitaltwins"); // Iterate over the twin instances in the pageable response. // The "await" keyword here is required because new pages will be fetched when necessary, // which involves a request to the service. await foreach (string response in asyncPageableResponse) { BasicDigitalTwin twin = JsonSerializer.Deserialize<BasicDigitalTwin>(response); Console.WriteLine($"Found digital twin '{twin.Id}'"); }
Exceptions

UpdateComponent(String, String, String, RequestOptions, CancellationToken)

Updates properties of a component on a digital twin synchronously.

Declaration
public virtual Azure.Response<string> UpdateComponent (string digitalTwinId, string componentPath, string componentUpdateOperations, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String componentPath

The component being modified.

String componentUpdateOperations

The application/json-patch+json operations to be performed on the specified digital twin's component.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

UpdateComponentAsync(String, String, String, RequestOptions, CancellationToken)

Updates properties of a component on a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<string>> UpdateComponentAsync (string digitalTwinId, string componentPath, string componentUpdateOperations, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin.

String componentPath

The component being modified.

String componentUpdateOperations

The application/json-patch+json operations to be performed on the specified digital twin's component.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellation token.

Returns
Examples
The exception is thrown when digitalTwinId or componentPath is null.
 // Update Component1 by replacing the property ComponentProp1 value, // using an optional utility to build the payload. var componentUpdateUtility = new UpdateOperationsUtility(); componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value"); string updatePayload = componentUpdateUtility.Serialize(); await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload); Console.WriteLine($"Updated component for digital twin '{basicDtId}'.");
Exceptions

UpdateDigitalTwin(String, String, RequestOptions, CancellationToken)

Updates a digital twin synchronously.

Declaration
public virtual Azure.Response<string> UpdateDigitalTwin (string digitalTwinId, string digitalTwinUpdateOperations, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin to update.

String digitalTwinUpdateOperations

The application/json-patch+json operations to be performed on the specified digital twin.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellationToken.

Returns
Exceptions
See Also

UpdateDigitalTwinAsync(String, String, RequestOptions, CancellationToken)

Updates a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response<string>> UpdateDigitalTwinAsync (string digitalTwinId, string digitalTwinUpdateOperations, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the digital twin to update.

String digitalTwinUpdateOperations

The application/json-patch+json operations to be performed on the specified digital twin.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellationToken.

Returns
Exceptions

UpdateRelationship(String, String, String, RequestOptions, CancellationToken)

Updates the properties of a relationship on a digital twin synchronously.

Declaration
public virtual Azure.Response UpdateRelationship (string digitalTwinId, string relationshipId, string relationshipUpdateOperations, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipId

The Id of the relationship to be updated.

String relationshipUpdateOperations

The application/json-patch+json operations to be performed on the specified digital twin's relationship.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions
See Also

UpdateRelationshipAsync(String, String, String, RequestOptions, CancellationToken)

Updates the properties of a relationship on a digital twin asynchronously.

Declaration
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateRelationshipAsync (string digitalTwinId, string relationshipId, string relationshipUpdateOperations, Azure.DigitalTwins.Core.RequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
String digitalTwinId

The Id of the source digital twin.

String relationshipId

The Id of the relationship to be updated.

String relationshipUpdateOperations

The application/json-patch+json operations to be performed on the specified digital twin's relationship.

RequestOptions requestOptions

The optional settings for this request.

CancellationToken cancellationToken

The cancellation token.

Returns
Exceptions