Computed Attribute API

MADCOW 4 years ago

Hello I read the documentation, I can add the calculated attributes, edit etc through the API, but I didn't find how to Define this calculated Attribute to a Device, User or Group through the API.

I've already searched for the source code and I didn't find it either.

Anton Tananaev 4 years ago

Have you looked at how the official web app does it?

MADCOW 4 years ago

Yes I saw the web app, I searched the JS but without understanding how it does the POST, in ComputedAttribute.js AllComputedAttributes.js etc

Anton Tananaev 4 years ago

Why do you need to search JS? You just need to look at the actual requests.

GB 4 years ago

You need to find out the attribute id and the vehicle id.
In possession of these two pieces of information and just make a POST or DELETE

Note: "Anton Tananaev" because if I do a POST 2 times with the same data, in the database the record is duplicated instead of replacing the existing one? Any compatibility with other banks?

let ATTRIBUTE_ID = 1, DEVICE_ID = 1;
let USER = "test", PASSWORD = "test";

$.ajax({
  url: `${URL_API}/api/permissions`,
  method: "DELETE",
  headers: {
    "content-type": "application/json",
    "authorization": "Basic " + btoa(`${USER}:${PASSWORD}`)
  },
  processData: false,
  data: JSON.stringify({attributeId: ATTRIBUTE_ID, deviceId: DEVICE_ID)
}).always(() => {
  $.ajax({
    url: `${URL_API}/api/permissions`,
    method: "POST",
    headers: {
      "content-type": "application/json",
      "authorization": "Basic " + btoa(`${USER}:${PASSWORD}`)
    },
    processData: false,
    data: JSON.stringify({attributeId: ATTRIBUTE_ID, deviceId: DEVICE_ID)
  });
}) 
GB 4 years ago

Fixing an error in the above code: (deviceId first / the order of the parameters affects the result)

data: JSON.stringify({deviceId: DEVICE_ID, attributeId: ATTRIBUTE_ID})

I couldn't edit