Documentation

Mistake on this page? Email us

ResourcesApi

Hierarchy

  • ApiBase
    • ResourcesApi

Index

Constructors

constructor

  • Parameters

    • Optional options: ConfigOptions
    • Default value responseHandler: function =¬†null
        • (sdkError: SDKError, response: superagent.Response): any
        • Parameters

          • sdkError: SDKError
          • response: superagent.Response

          Returns any

    Returns ResourcesApi

Methods

complete

  • complete(error: any, response: any, acceptHeader: string, callback?: function): void
  • Parameters

    • error: any
    • response: any
    • acceptHeader: string
    • Optional callback: function
        • Parameters

          Returns any

    Returns void

currentConfig

  • currentConfig(): object
  • Returns the current configuration of this API module

    Returns object

    • apiKey: any
    • host: any

deleteResourcePath

  • deleteResourcePath(deviceId: string, resourcePath: string, noResp?: boolean, callback?: function, requestOptions?: object): superagent.SuperAgentRequest
  • Delete a resource path A request to delete a resource path must be handled by both Device Management Client and Device Management Connect. All resource APIs are asynchronous. These APIs respond only if the device is turned on and connected to Device Management Connect and there is an active notification channel. Example usage: curl -X DELETE \ https://api.us-east-1.mbedcloud.com/v2/endpoints/{device-id}/{resourcePath} \ -H 'authorization: Bearer {api-key}'

    Parameters

    • deviceId: string

      A unique Device Management device ID for the endpoint. Note that the ID must be an exact match. You cannot use wildcards here.

    • resourcePath: string

      The URL of the resource.

    • Optional noResp: boolean

      If you make a request with `noResp=true`, Device Management Connect makes a CoAP non-confirmable request to the device. Such requests are not guaranteed to arrive in the device, and you do not get back an async-response-id. If calls with this parameter enabled succeed, they return with the status code `204 No Content`. If the underlying protocol does not support non-confirmable requests, or if the endpoint is registered in queue mode, the response is status code `409 Conflict`.

    • Optional callback: function
        • (error: any, data?: AsyncID, response?: superagent.Response): any
        • Parameters

          • error: any
          • Optional data: AsyncID
          • Optional response: superagent.Response

          Returns any

    • Optional requestOptions: object
      • [key: string]: any

    Returns superagent.SuperAgentRequest

executeOrCreateResource

  • executeOrCreateResource(deviceId: string, resourcePath: string, resourceFunction?: string, noResp?: boolean, callback?: function, requestOptions?: object): superagent.SuperAgentRequest
  • Execute a function on a Resource or create new Object instance With this API, you can execute a function on an existing resource and create new Object instance to the device. The resource-path does not have to exist - it can be created by the call. The maximum length of resource-path is 255 characters. All resource APIs are asynchronous. These APIs respond only if the device is turned on and connected to Device Management Connect and there is an active notification channel. Supported content types depend on the device and its resource. Device Management translates HTTP to equivalent CoAP content type. Example usage: This example resets the min and max values of the temperature sensor instance 0 by executing the Resource 5605 'Reset Min and Max Measured Values'. curl -X POST \ https://api.us-east-1.mbedcloud.com/v2/endpoints/{device-id}/3303/0/5605 \ -H 'authorization: Bearer {api-key}'

    Parameters

    • deviceId: string

      A unique Device Management device ID for the endpoint. Note that the ID must be an exact match. You cannot use wildcards here.

    • resourcePath: string

      The URL of the resource.

    • Optional resourceFunction: string

      This value is not needed. Most of the time resources do not accept a function but they have their own functions predefined. You can use this to trigger them. If a function is included, the body of this request is passed as a char* to the function in Device Management Client.

    • Optional noResp: boolean

      If you make a request with `noResp=true`, Device Management Connect makes a CoAP non-confirmable request to the device. Such requests are not guaranteed to arrive in the device, and you do not get back an async-response-id. If calls with this parameter enabled succeed, they return with the status code `204 No Content`. If the underlying protocol does not support non-confirmable requests, or if the endpoint is registered in queue mode, the response is status code `409 Conflict`.

    • Optional callback: function
        • (error: any, data?: AsyncID, response?: superagent.Response): any
        • Parameters

          • error: any
          • Optional data: AsyncID
          • Optional response: superagent.Response

          Returns any

    • Optional requestOptions: object
      • [key: string]: any

    Returns superagent.SuperAgentRequest

getResourceValue

  • getResourceValue(deviceId: string, resourcePath: string, cacheOnly?: boolean, noResp?: boolean, callback?: function, requestOptions?: object): superagent.SuperAgentRequest
  • Read from a resource Requests the resource value either from the device or cache. If the value is not in the cache, the request goes all the way to the device. When the response is available, an `AsyncIDResponse` json object is received in the notification channel. The resource values can be also in cache based on `max_age` defined by the device side. The value found from the cache is returned immediately in the response. The preferred way to get resource values is to use the subscribe and callback methods. All resource APIs are asynchronous. These APIs only respond if the device is turned on and connected to Device Management. See also how resource caching works. Please refer to Lightweight Machine to Machine Technical specification for more inforamtion. Example usage: curl -X GET \ https://api.us-east-1.mbedcloud.com/v2/endpoints/{device-id}/{resourcePath} \ -H 'authorization: Bearer {api-key}'

    Parameters

    • deviceId: string

      Unique Device Management device ID for the endpoint. Note that the ID needs to be an exact match. You cannot use wildcards here.

    • resourcePath: string

      The URL of the resource.

    • Optional cacheOnly: boolean

      If true, the response comes only from the cache. Default: false. Device Management Connect caches the received resource values for the time of max_age defined in the client side.

    • Optional noResp: boolean

      If a request is made with `noResp=true`, Device Management Connect makes a CoAP non-confirmable request to the device. Such requests are not guaranteed to arrive in the device, and you do not get back an async-response-id. If calls with this parameter enabled succeed, they return with the status code `204 No Content`. If the underlying protocol does not support non-confirmable requests, or if the endpoint is registered in queue mode, the response is status code `409 Conflict`.

    • Optional callback: function
        • (error: any, data?: any, response?: superagent.Response): any
        • Parameters

          • error: any
          • Optional data: any
          • Optional response: superagent.Response

          Returns any

    • Optional requestOptions: object
      • [key: string]: any

    Returns superagent.SuperAgentRequest

request

  • request<T>(options: object, callback?: function): superagent.SuperAgentRequest
  • Type parameters

    • T

    Parameters

    • options: object
      • acceptTypes: Array<string>
      • Optional body?: any
      • contentTypes: Array<string>
      • Optional file?: boolean
      • formParams: __type
      • headers: object
        • [key: string]: string
      • method: string
      • query: __type
      • Optional requestOptions?: object
        • [key: string]: any
      • url: string
      • useFormData: boolean
    • Optional callback: function
        • Parameters

          Returns any

    Returns superagent.SuperAgentRequest

updateResourceValue

  • updateResourceValue(deviceId: string, resourcePath: string, resourceValue: string, noResp?: boolean, callback?: function, requestOptions?: object): superagent.SuperAgentRequest
  • Write to a Resource or use write-attributes (notification rules) for a Resource With this API, you can write a new value to existing Resources or use the write attributes to set the notification rules for the Resources. The notification rules only work on the device client side and may not be supported by all clients. This API can also be used to transfer files to the device. Device Management Connect LwM2M server implements the Option 1 from RFC7959. The maximum block size is 1024 bytes. The block size versus transferred file size is something to note in low quality networks. The customer application needs to know what type of file is transferred (for example txt) and the payload can be encrypted by the customer. The maximum size of payload is 1048576 bytes. All resource APIs are asynchronous. These APIs respond only if the device is turned on and connected to Device Management Connect and there is an active notification channel. Supported content types depend on the device and its resource. Device Management translates HTTP to equivalent CoAP content type. Example usage: This example sets the alarm on a buzzer. The command writes the Buzzer instance 0, &quot;On/Off&quot; boolean resource to '1'. curl -X PUT \ https://api.us-east-1.mbedcloud.com/v2/endpoints/{device-id}/3338/0/5850 -H &quot;content-type: text/plain&quot; \ -H 'authorization: Bearer {api-key}' -d '1'

    Parameters

    • deviceId: string

      A unique Device Management device ID for the endpoint. Note that the ID must be an exact match. You cannot use wildcards here.

    • resourcePath: string

      Resource URL.

    • resourceValue: string

      The value to be set to the resource.

    • Optional noResp: boolean

      If you make a request with `noResp=true`, Device Management Connect makes a CoAP non-confirmable request to the device. Such requests are not guaranteed to arrive in the device, and you do not get back an async-response-id. If calls with this parameter enabled succeed, they return with the status code `204 No Content`. If the underlying protocol does not support non-confirmable requests, or if the endpoint is registered in queue mode, the response is status code `409 Conflict`.

    • Optional callback: function
        • (error: any, data?: AsyncID, response?: superagent.Response): any
        • Parameters

          • error: any
          • Optional data: AsyncID
          • Optional response: superagent.Response

          Returns any

    • Optional requestOptions: object
      • [key: string]: any

    Returns superagent.SuperAgentRequest