Hi @Lucía Sánchez Greetings! Welcome to Microsoft Q&A forum. Thank you for posting your question here. We would be glad to help you on this.
To get started with creating you custom Azure Digitial Twins, you would first need create a Digital Twin model which acts as template for your Digital Twin. Azure Digital Twins models are represented in the JSON-LD-based Digital Twin Definition Language (DTDL). An Azure Digital Twin model has different fields associated with it. Please find the below image for more details
Please refer the documentation on Model Overview which provides details on different sections of the Azure Digital Twin model and DTDL repository which provides several examples on how you can design a model compatible to your needs.
Once you have the model created, you can follow the steps in the Code a Client App article and use the code sample from Upload the model section to create the model on your Azure Digital Twin instance. After uploading the model, you can generate Digital Twins based off the model using the code sample provided in Create Digital Twins section. Here is the code snippet for your reference.
// <Model_code>
Console.WriteLine();
Console.WriteLine($"Upload a model");
string dtdl = File.ReadAllText("SampleModel.json");
var models = new List<string> { dtdl };
// Upload the model to the service
// <Model_try_catch>
try
{
await client.CreateModelsAsync(models);
Console.WriteLine("Models uploaded to the instance:");
}
catch (RequestFailedException e)
{
Console.WriteLine($"Upload model error: {e.Status}: {e.Message}");
}
// <Initialize_twins>
var twinData = new BasicDigitalTwin();
twinData.Metadata.ModelId = "dtmi:example:SampleModel;1";
twinData.Contents.Add("data", $"Hello World!");
string prefix = "sampleTwin-";
for (int i = 0; i < 3; i++)
{
try
{
twinData.Id = $"{prefix}{i}";
await client.CreateOrReplaceDigitalTwinAsync<BasicDigitalTwin>(twinData.Id, twinData);
Console.WriteLine($"Created twin: {twinData.Id}");
}
catch(RequestFailedException e)
{
Console.WriteLine($"Create twin error: {e.Status}: {e.Message}");
}
}
Hope this helps! Please let us know if you have any further questions or need further clarification in the comments below. We would be glad to assist you further. If the response helped, please do click Accept Answer and Yes. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.