Documentation

Mistake on this page? Email us

Device Directory API

The API can be initalized with a .env file in the working directory with the following values

MBED_CLOUD_SDK_API_KEY=

and optionally

MBED_CLOUD_SDK_HOST= (defaults to https://api.us-east-1.mbedcloud.com)

OR

This API is initialized with ConnectionOptions.

To create an instance of this API in Node.js:

var PelionDMSDK = require("mbed-cloud-sdk");

var devices = new PelionDMSDK.DeviceDirectoryApi({
    apiKey: "<Pelion DM API Key>"
});

To create an instance of this API in the browser:

<script src="<pelion-dm-sdk>/bundles/device-directory.min.js"></script>

<script>
    var devices = new MbedCloudSDK.DeviceDirectoryApi({
        apiKey: "<Pelion DM API Key>"
    });
</script>

Hierarchy

  • DeviceDirectoryApi

Index

Constructors

constructor

Methods

addDevice

  • Add a device

    Example:

    devices.addDevice({
        certificateFingerprint: '07:7A:EB:67:37:42:4D:11:5C:3E:99:07:1E:EB:44:...',
        certificateIssuerId: '015c3c457b2002420a01041603c00000',
        name: 'newDeviceName'
    })
    .then(device => {
        // Utilize device here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    Returns Promise<Device>

    Promise of device

  • Add a device

    Example:

    devices.addDevice({
        certificateFingerprint: '07:7A:EB:67:37:42:4D:11:5C:3E:99:07:1E:EB:44:...',
        certificateIssuerId: '015c3c457b2002420a01041603c00000',
        name: 'newDeviceName'
    }, function(error, device) {
        if (error) throw error;
        // Utilize device here
    });

    Parameters

    Returns void

addQuery

  • Add a query

    Example:

    devices.addQuery({
        name: 'TestFilter',
        description: 'Description here',
        filter: {
            state: { $eq: "bootstrapped" },
            createdAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") },
            updatedAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") }
        }
    })
    .then(query => {
        // Utilize query here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    Returns Promise<Query>

    Promise of query

  • Add a query

    Example:

    devices.addQuery({
        name: 'TestFilter',
        description: 'Description here',
        filter: {
            state: { $eq: "bootstrapped" },
            createdAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") },
            updatedAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") }
        }
    }, function(error, query) {
        if (error) throw error;
        // Utilize query here
    });

    Parameters

    Returns void

deleteDevice

  • deleteDevice(deviceId: string): Promise<void>
  • Delete a device

    Example:

    devices.deleteDevice('015c5ed320c0000000000001001000f0')
    .catch(error => {
        console.log(error);
    });

    Parameters

    • deviceId: string

      Device ID

    Returns Promise<void>

    Promise containing any error

  • deleteDevice(deviceId: string, callback: CallbackFn<void>): void
  • Delete a device

    Example:

    devices.deleteDevice('015c5ed320c0000000000001001000f0', function(error) {
        if (error) throw error;
    });

    Parameters

    • deviceId: string

      Device ID

    • callback: CallbackFn<void>

      A function that is passed any error

    Returns void

deleteQuery

  • deleteQuery(queryId: string): Promise<void>
  • Delete a query

    Example:

    devices.deleteQuery('015c45eb321700000000000100100155')
    .catch(error => {
        console.log(error);
    });

    Parameters

    • queryId: string

      query ID

    Returns Promise<void>

    Promise containing any error

  • deleteQuery(queryId: string, callback: CallbackFn<void>): void
  • Delete a query

    Example:

    devices.deleteQuery('015c45eb321700000000000100100155', function(error) {
        if (error) throw error;
    });

    Parameters

    • queryId: string

      query ID

    • callback: CallbackFn<void>

      A function that is passed any error

    Returns void

getDevice

  • getDevice(deviceId: string): Promise<Device>
  • Gets details of a device

    Example:

    devices.getDevice('015c5ed320c0000000000001001000f0')
    .then(device => {
        // Utilize device here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    • deviceId: string

      Device ID

    Returns Promise<Device>

    Promise of device

  • Gets details of a device

    Example:

    devices.getDevice('015c5ed320c0000000000001001000f0', function(error, device) {
        if (error) throw error;
        // Utilize device here
    });

    Parameters

    • deviceId: string

      Device ID

    • callback: CallbackFn<Device>

      A function that is passed the arguments (error, device)

    Returns void

getDeviceEvent

  • getDeviceEvent(deviceEventId: string): Promise<DeviceEvent>
  • Get a single device event

    Example:

    devices.getDeviceEvent('015c45eb321700000000000100100155')
    .then(deviceevent => {
        // Utilize deviceevent here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    • deviceEventId: string

      device event ID

    Returns Promise<DeviceEvent>

    Promise of device event

  • getDeviceEvent(deviceEventId: string, callback: CallbackFn<DeviceEvent>): void
  • Get a single device event

    Example:

    devices.getDeviceEvent('015c45eb321700000000000100100155', function(error, deviceevent) {
        if (error) throw error;
        // Utilize deviceevent here
    });

    Parameters

    • deviceEventId: string

      device event ID

    • callback: CallbackFn<DeviceEvent>

      A function that is passed the return arguments (error, device event)

    Returns void

getLastApiMetadata

  • getLastApiMetadata(): Promise<ApiMetadata>
  • Get meta data for the last Pelion Device Management API call

    Returns Promise<ApiMetadata>

    Promise of meta data

  • getLastApiMetadata(callback: CallbackFn<ApiMetadata>): void
  • Get meta data for the last Pelion Device Management API call

    Parameters

    • callback: CallbackFn<ApiMetadata>

      A function that is passed the arguments (error, meta data)

    Returns void

getQuery

  • getQuery(queryId: string): Promise<Query>
  • Get a query

    Example:

    devices.getQuery('015c45eb321700000000000100100155')
    .then(query => {
        // Utilize query here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    • queryId: string

      query ID

    Returns Promise<Query>

    Promise of query

  • Get a query

    Example:

    devices.getQuery('015c45eb321700000000000100100155', function(error, query) {
        if (error) throw error;
        // Utilize query here
    });

    Parameters

    • queryId: string

      query ID

    • callback: CallbackFn<Query>

      A function that is passed the arguments (error, query)

    Returns void

    Promise of query

listDeviceEvents

  • List device events

    Example:

    devices.listDeviceEvents({
        limit: 50,
        filter: {
            deviceId: { $eq: "015c45eb321700000000000100100155" },
            eventDate: { $gte: new Date("01-01-2016"), $lte: new Date("01-01-2018") }
        }
    })
    .then(deviceevents => {
        // Utilize deviceevents here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    Returns Promise<ListResponse<DeviceEvent>>

    Promise of listResponse

  • List device events

    Example:

    devices.listDeviceEvents({
        limit: 50,
        filter: {
            deviceId: { $eq: "015c45eb321700000000000100100155" },
            eventDate: { $gte: new Date("01-01-2016"), $lte: new Date("01-01-2018") }
        }
    }, function(error, deviceevents) {
        if (error) throw error;
        // Utilize deviceevents here
    });

    Parameters

    Returns void

listDevices

  • Gets a list of devices

    Example:

    devices.listDevices({
        filter: {
            state: { $eq: "bootstrapped" },
            createdAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") },
            updatedAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") }
        }
    })
    .then(devices => {
        // Utilize devices here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    Returns Promise<ListResponse<Device>>

    Promise of devices

  • Gets a list of devices

    Example:

    devices.listDevices({
        filter: {
            state: { $eq: "bootstrapped" },
            createdAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") },
            updatedAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") }
        }
    }, function(error, devices) {
        if (error) throw error;
        // Utilize devices here
    });

    Parameters

    Returns void

listQueries

  • List queries

    Example:

    devices.listQueries({limit: 5})
    .then(queries => {
        // Utilize queries here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    Returns Promise<ListResponse<Query>>

    Promise containing a list response

  • List queries

    Example:

    devices.listQueries({limit: 5}, function(error, queries) {
        if (error) throw error;
        // Utilize queries here
    });

    Parameters

    Returns void

    Promise containing a list response

updateDevice

  • Update a device

    Example:

    devices.updateDevice({
        id: '015c5ed320c0000000000001001000f0',
        name: 'Updated name',
        description: 'Updated description',
        customAttributes: {
            attr1: 'Use json structure',
            attr2: 'Can use 5 entries in the JSON struct'
        }
    })
    .then(device => {
        // Utilize device here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    Returns Promise<Device>

    Promise of device

  • Update a device

    Example:

    devices.updateDevice({
        id: '015c5ed320c0000000000001001000f0',
        name: 'Updated name',
        description: 'Updated description',
        customAttributes: {
            attr1: 'Use json structure',
            attr2: 'Can use 5 entries in the JSON struct'
        }
    }, function(error, device) {
        if (error) throw error;
        // Utilize device here
    });

    Parameters

    Returns void

updateQuery

  • Update a query

    Example:

    devices.updateQuery({
        name: 'TestFilter',
        id: '015c45eb321700000000000100100155',
        filter: {
            state: { $eq: "bootstrapped" },
            createdAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") },
            updatedAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") }
        }
    })
    .then(query => {
        // Utilize query here
    })
    .catch(error => {
        console.log(error);
    });

    Parameters

    Returns Promise<Query>

    Promise of query

  • Update a query

    Example:

    devices.updateQuery({
        name: 'TestFilter',
        id: '015c45eb321700000000000100100155',
        filter: {
            state: { $eq: "bootstrapped" },
            createdAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") },
            updatedAt: { $gte: new Date("01-01-2014"), $lte: new Date("01-01-2018") }
        }
    }, function(error, query) {
        if (error) throw error;
        // Utilize query here
    });

    Parameters

    Returns void