Waziup / api-server

3 stars 6 forks source link

"The entity does not have such an attribute" #32

Open cdupont opened 6 years ago

cdupont commented 6 years ago

When trying to add a name to a sensor without a name:

$ curl -X PUT "http://localhost:80/api/v1/domains/waziup/sensors/MySensor/name" -H  "accept: application/json" -H  "Authorization: Bearer $TOKEN" -H  "Content-Type: text/plain" -d "Sensor1"
{
  "error": "NotFound",
  "description": "The entity does not have such an attribute"
}
cdupont commented 6 years ago

Usually PUT is for modifying an existing resource, POST is for creating a new one. For instance modifying the name attribute in Orion is:

PUT http://orion:1026/v2/entities/MySensor/attrs/name -d MySensor

while adding the name attribute is:

POST http://orion:1026/v2/entities/MySensor/attrs -d {id: name, value:MySensor}

However adding both methods in the API seems too much...

cdupont commented 6 years ago

@henokzion any idea? A solution could be to add a default or null value to the "name" attribute upon creating the sensor...

cdupont commented 6 years ago

OK I put some default values when creating the sensors for name, owner, domain, gateway_id and location: https://github.com/Waziup/api-server/commit/99efe41f87f359b8486dd6b7d4c34731c64e3050 So now it should be possible to perform a PUT on them.

henokzion commented 6 years ago

Putting the default name is a good Idea. I will test it now

cdupont commented 6 years ago

@henokzion did you test?