Patch request for keg volumes

Hi @mikey,

I’ve managed to get requests to pass successfully, however it seems like my keg isnt actually being updated on the taplist server side. Here is the code

const Auth = require("../models/auth");

const servedController = async (req, res) => {
  try {
    const { currentTapNumber, servedAmount } = req.body;
    const parsedServedAmount = parseInt(servedAmount);
    console.log(parsedServedAmount);
    console.log(currentTapNumber);
    const details = await Auth.find();
    const venue = details[0].venue;
    const auth_token = details[0].auth_token;
    const response = await fetch(
      `https://api.taplist.io/api/v1/venues/${venue}/taps/${currentTapNumber}/current-keg`,
      {
        method: "PATCH",
        headers: { Authorization: `Token ${auth_token}` },
        body: JSON.stringify({
          add_served_volume_ml: parsedServedAmount,
        }),
      }
    );
    const data = await response.json();
    console.log("keg volume updated");
    res.status(200).json(data);
  } catch (err) {
    console.error("Error occurred while fetching taps:", err);
    res.status(500).json({
      error: `An error occurred while fetching taps: ${err.message}`,
    });
  }
};

module.exports = servedController;

if I manually set currentTapNumber to 1 and parsedServedAmount to 1500, nothing gets uodated. Can you spot what I’m doing wrong?

Thanks

EDIT: Spotted it, wasn’t defining the content as a json

Is there a way to reset the keg volume? Ive tried this, but it seems it wont allow me to patch that part of the object

const Auth = require("../models/auth");

const resetController = async (req, res) => {
  try {
    const { currentTapNumber, fullVolume } = req.body;
    console.log(req.body);
    const parsedFullVolume = parseInt(fullVolume);
    const details = await Auth.find();
    const venue = details[0].venue;
    const auth_token = details[0].auth_token;
    const response = await fetch(
      `https://api.taplist.io/api/v1/venues/${venue}/taps/${currentTapNumber}/current-keg`,
      {
        method: "PATCH",
        headers: {
          Authorization: `Token ${auth_token}`,
          "Content-Type": "application/json",
        },

        body: JSON.stringify({
          remaining_volume_ml: parsedFullVolume,
        }),
      }
    );
    const data = await response.json();
    console.log("keg volume reset");
    res.status(200).json(data);
  } catch (err) {
    console.error("Error occurred while updating tap volume:", err);
    res.status(500).json({
      error: `An error occurred while updatng tap volume: ${err.message}`,
    });
  }
};

module.exports = resetController;

remaining_volume_ml is derived; patch served_volume_ml to zero and you should be good!