problems with API requests with PUT method

Matheus Alves4 years ago

I'm trying to update device via API request with PUT method,
But the error 400 always returns me, I've checked the authentication user and it's right.
this error only occurs with the PUT method.
Code:

const updateEntity = (id, newData, entity) => {
  const userEncode = base64.encode('user' + ':' + 'password');
  const requestOptions = {
    method: 'PUT',
    headers: {
      "Authorization": `Basic ${userEncode}`,
      'Content-Type': 'application/json',
    },
    body:  JSON.stringify(newData),
  };
  fetch(`http://207.180.198.226:8082/api/${entity}/${id}`, requestOptions)
    .then((response) => console.log(response));
};

updateEntity(512, {"model": "TK311C"}, 'devices');
Anton Tananaev4 years ago

You have to send full model.

Matheus Alves4 years ago

It worked, Thanks!
I realized that it is mandatory to pass in the body the keys "id", "name" and "uniqueId".

Anton Tananaev4 years ago

Once again, you have to pass the whole model, not just some specific fields.

Matheus Alves4 years ago

Ok, Thanks!