This package contains an isomorphic SDK for Azure Digital Twins API to provide access to the Azure Digital Twins service for managing twins, models, relationships, etc.
npm install @azure/digital-twins-core
npm install @azure/ms-rest-nodeauth
import * as coreHttp from "@azure/core-http";
import * as coreArm from "@azure/core-arm";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import {
AzureDigitalTwinsAPI,
AzureDigitalTwinsAPIModels,
AzureDigitalTwinsAPIMappers
} from "@azure/digital-twins-core";
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
msRestNodeAuth
.interactiveLogin()
.then((creds) => {
const client = new AzureDigitalTwinsAPI(creds, subscriptionId);
const dependenciesFor = ["testdependenciesFor"];
const includeModelDefinition = true;
const maxItemCount = 1;
client.digitalTwinModels
.list(dependenciesFor, includeModelDefinition, maxItemCount)
.then((result) => {
console.log("The result is:");
console.log(result);
});
}
.catch((err) => {
console.error(err);
})
npm install @azure/ms-rest-browserauth
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/digital-twins-core sample</title>
<script src="node_modules/@azure/core-http/dist/coreHttp.browser.js"></script>
<script src="node_modules/@azure/core-arm/dist/coreArm.js"></script>
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
<script src="node_modules/@azure/digital-twins-core/dist/digital-twins-core.js"></script>
<script type="text/javascript">
const subscriptionId = "<Subscription_Id>";
const authManager = new msAuth.AuthManager({
clientId: "<client id for your Azure AD app>",
tenant: "<optional tenant for your organization>"
});
authManager.finalizeLogin().then((res) => {
if (!res.isLoggedIn) {
// may cause redirects
authManager.login();
}
const client = new Azure.Digitaltwins.AzureDigitalTwinsAPI(res.creds, subscriptionId);
const dependenciesFor = ["testdependenciesFor"];
const includeModelDefinition = true;
const maxItemCount = 1;
client.digitalTwinModels
.list(dependenciesFor, includeModelDefinition, maxItemCount)
.then((result) => {
console.log("The result is:");
console.log(result);
})
.catch((err) => {
console.log("An error occurred:");
console.error(err);
});
});
</script>
</head>
<body></body>
</html
Azure Digital Twins Preview is an Azure IoT service that creates comprehensive models of the physical environment. It can create spatial intelligence graphs to model the relationships and interactions between people, spaces, and devices. You can learn more about Azure Digital Twins by visiting Azure Digital Twins Documentation
Please take a look at the Readme file in samples directory for detailed examples on how to use this library.
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL
environment variable to info
. Alternatively, logging can be enabled at runtime by calling setLogLevel
in the @azure/logger
:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.
Please take a look at the samples directory for detailed examples on how to use this library.
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
Generated using TypeDoc