0
votes

I've created a device on Watson IoT Plattform online dashboard. This device published data using Basic authentication with use-token-auth and its password:

URL: https://noz238.messaging.internetofthings.ibmcloud.com:8883/api/v0002/device/types/Light/devices/TestLight/events/status
Method: POST    
Body: {"isOn":false}

This send body is visible on the latest events view on https://noz238.internetofthings.ibmcloud.com/dashboard/devices/browse

I have problems to get the latest state / event of this device using this REST API (and with an API key for visualizations). I did got unexpected responses trying different api's

I tried this endpoint: https://noz238.internetofthings.ibmcloud.com/api/v0002/device/types/Light/devices/TestLight/events (https://docs.internetofthings.ibmcloud.com/apis/swagger/v0002/info-mgmt.html#/Last%20Event%20Cache/get_device_types__deviceType__devices__deviceId__events)

Answer: RC: 403

{
    "message": "CUDCS0106E: <missing messageId in bundle com.ibm.wiotp.util.httpservice.nls.servicemessages>",
    "exception": {
        "id": "CUDCS0106E",
        "properties": [
            "noz238"
        ]
    }
}

And I tried this endpoint: https://noz238.internetofthings.ibmcloud.com/api/v0002/device/types/Light/devices/TestLight/state/test (https://docs.internetofthings.ibmcloud.com/apis/swagger/v0002/state-mgmt.html#/Devices/get_device_types__typeId__devices__deviceId__state__logicalInterfaceId_)

Answer: RC: 404

{
    "message": "CUDIM0001E: No 'Device Type' with id 'Light' could be found in org 'noz238'",
    "exception": {
        "id": "CUDIM0001E",
        "properties": [
            "noz238",
            "Light",
            "Device Type"
        ]
    }
}

How can I get the latest event / state of a device?

1

1 Answers

0
votes

I am not sure if you found out already, but there is in the dashboard in the right top a question mark, there you can access all the API using swagger, the swagger will give you a better understanding of what are the endpoints that you need to use.

The device Type is one thing the device ID is another thing, probably you are not getting the right deviceID.

This command would give you all the devices that you have.

curl -X GET "https://noz238.internetofthings.ibmcloud.com/api/v0002/bulk/devices?_limit=25" -H "accept: application/json"

This command would give you all the logs for that device

curl -X GET "https://noz238.internetofthings.ibmcloud.com/api/v0002/device/types/{DEVICE_TYPE}/devices/{DEVICE_ID}/diag/logs" -H "accept: application/json"

here you can access all the endpoints that are available in the swagger documentation

https://noz238.internetofthings.ibmcloud.com/docs/index.html