1

I am developing a react app over DHIS2 and data online that is structured like:

indicators: [
  {
   name: "something",
   attributeValues : [ {}],
   anotherNode: "anything",

  },
 {},
 {}, ...
]

I am trying to update the whole attributeValues Node. I'm using a fetch request, but getting

405 method not allowed

What do you suppose i'm doing wrong. This is the fetch post request i wrote.

let dataToSend = {
  lastUpdated: currentTime,
  created: currentTime,
  value: newName,
  attribute: {
    id: indicatorID,
  },
};

fetch(`https://www.namis.org/namis1/api/indicators/${id}/attributeValues`, {
  body: JSON.stringify(dataToSend),
  headers: {
    Authorization: basicAuth,
    "Content-type": "application/json",
  },
  method: "POST",
}).then((response) => response.json());

If the question happens to be a duplication, please direct me to the possible already existing solution.

Regards.

1
  • dhis2 is responding that the method POSTis not allowed in the endpoint /api/indicators/ID/attributeValues. You can try to update the whole indicator with a PUT or other ways. The best way to find out what to do is to open developer console and do the same in the interface (add attributeValues to indicator) and see what the network tab in the developer console does. Commented Aug 13, 2020 at 7:21

1 Answer 1

1

so the issue got resolved. I don't know if its the DHIS2 system or something, but I can't update just one node of an indicator, also because POST is for creating nodes that don't exist.

So the correct way to use a PUT request, and also at the same time, instead of just passing the new data to the attributeValues node, am updating the whole indicator node i.e the corrent way should be :

let dataToSend =  {
 name: "something",
 attributeValues : [ {
   lastUpdated: currentTime,
   created: currentTime,
   value: newName,
   attribute: {
     id: indicatorID}
 }],
anotherNode: "anything"}



fetch(`https://www.namis.org/namis1/api/indicators/${id}`, {
body: JSON.stringify(dataToSend),
headers: {
  Authorization: basicAuth,
  "Content-type": "application/json",
  },
  method: "PUT",
  }).then((response) => response.json());

SO the end point is the indicatorID, and the data-to-send also includes other nodes in the indicator to be updated, what changes is the attributeValue node only.

If anyone meets the same challenge and is unable to understand this answer, contact me for more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.