Closed edgarsilva closed 9 years ago
You receive "Not Authorized", because you probably used user token, not device one (which is acquired during device activation process and cannot be retrieved again).
When you add component to a device, its type must be already defined in account catalog. In POST /accounts/{accountId}/devices/{deviceId}/components you should pass unique id (we suggest using UUID), custom name and type of component from available catalog.
Default component types are for example: temperature.v1.0, humidity.v1.0 and powerswitch.v1.0 which is an actuator (you can send messages back to device). You can retrieve list of catalog items using: https://github.com/enableiot/iotkit-api/wiki/Component-Types-Catalog#list-all-component-types-for-an-account
@mtomczew thanks for the quick response, should I then create a new device and activate it to retrieve the device token? then add all components right away (since cannot be retrieved again) is this the correct way to do it?
Regarding the component types, that is what I'm using to list them. I'll try again activating a device and getting that device's token, I'll update here afterwards.
One last question, are you planning on having an endpoint (or other way) to retrieve the deviceToken
for already activated devices? or is this a security measure? not being able to retrieve it again that is.
Nice this seems to be working, I'm closing the issue.
As you mentioned I was using the user token instead of the device token, getting the device token fixed it.
Thanks for the help.
@edgarsilva, glad you got it working. Yes, normally, you would normally set your device-id and activate your device to get the device token. The device token is stored in data/device.json (or certs/token.json in older agents). You need to keep it as you currently can't retrieve or regenerate it. You use the device token to register components (e.g., 'temp') since they are device-specific. The device token is also required when submitting data. The user token is used in almost all other cases (e.g., getting device info, component info and executing data queries).
mmm... Ok, thanks. Would be good to include this information somewhere in the docs, at least an explanation of device_token vs user_token, since I could not find anything regarding the difference and how to use those two; either in the wiki or the intel IoT site.
The exact same info in this issue would've saved me a couple of hours of testing and trial and error. So this info should be useful to other developers.
Thanks for the feedback. The token types are described in the API intro but it may help to link references to the tokens back to this page: https://github.com/enableiot/iotkit-api/wiki/Api-Home#authorization-tokens Actually, it sounds like you're not using the agent software on the device and doing everything using REST. In this case, you need to save the device token yourself after you get it by activating.
You are correct, I'm using REST, and yeap already taking into account saving the device's token.
Yeah it can come in handy to cross reference with that page.
Thanks for the help and quick response, I will let you know if anything comes up.
Hi,
I'm trying to add a component to a device as specified in this section of the wiki:
https://github.com/enableiot/iotkit-api/wiki/Device-Management#add-a-component-to-a-device
But I always get this error back when passing params:
If I change the endpoint to
GET /accounts/account_id/devices/<device_id>
I can see the device info, also this endpoint returns a list of components/accounts/<account_id>/cmpcatalog?full=true
Validation seems to work, this is what I get with no params passed:
This is what I'm passing to the request as POST JSON:
One other thing the docs seem to be incorrect, since they specify to pass these params:
as you can see the
cid
value does not match any type of component id in the returned list of components. Also type should besensor
oractuator
right? Lastly should the name be the dimension param specified in the component (name in the UI) or just any name for the relationship between the device and the component?Any help would be appreciated, thanks.