Update Trello Card with Google Apps Scripts

I am trying to update a Trello card based on a specific cell changed with google apps scripts. When I update something on the google sheet, it creates another copy with the updated info of the card in Trello. The card that was supposed to update doesn’t.

The strange thing is, sometimes it works. The times when I have seen it work was when I moved that card to a different list in the same board. It also sometimes creates a copy as well.

I have posted my code for google apps scripts on the bottom of this text. Any help would be welcomed!

//** To see how the object is structured, visit **
// https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put

const ui = SpreadsheetApp.getUi();
const boardId = 'xxxxxxxxxxxxxxxxxx';
const key = 'xxxxxxxxxxxxxxxxxx';
const token = 'xxxxxxxxxxxxxxxxxx';

const atEdit = (e) => {
  const {range: {getRow, getColumn}} = e;
  const [row, column] = [getRow(), getColumn()];

  const {getRange} = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  //Syntax for a single element is .getRange(row, column)
  const [affectedCell, getRangeCells] = [getRange(row, column).getValues(), getRange(row, 1, 1, 23)];
  const googleSheetsRowId = getRangeCells.getValues()[0][0];

  getCard(googleSheetsRowId, affectedCell);
}

const getCard = (rowId, getAffectedCell) => {
  const boardUrl = 'https://api.trello.com/1/boards/' + boardId + '/cards?key=' + key + '&token=' + token;
  const response = UrlFetchApp.fetch(boardUrl);
  
  const trelloCards = JSON.parse(response);
  const {id: trelloCardId} = trelloCards[rowId];
  ui.alert(Object.keys(trelloCards[rowId]));
  updateCard(trelloCardId, getAffectedCell);
}

const buildURL = (params) => {
  var esc = encodeURIComponent;
  var query = Object.keys(params)
    .map(key => esc(key) + '=' + esc(params[key]))
    .join('&');
  return query;
}

const updateCard = (cardId, affectedData) => {
  // For now, this only works for the name but my next task is for it to work on all the values >_<
  const data = {
    'name': affectedData[0][0],
    'desc': 'sup yo',
  };
  const options = {
    'method' : 'PUT',
    'payload' : JSON.stringify(data),
    'muteHttpExceptions': true
  };

  const updateUrl = 'https://api.trello.com/1/cards/' + cardId + '?key=' + key +'&token='+ token + '&' + buildURL(data);   

  const response = UrlFetchApp.fetch(updateUrl, options);

  ErrHTTP(response);
}

const ErrHTTP = (response) => {
  const responseCode = response.getResponseCode();
  const responseBody = response.getContentText();

  if (responseCode === 200) {
    ui.alert('You got it!');
  } else {
    ui.alert(Utilities.formatString("Request failed. Expected 200, got %d: %s", responseCode, responseBody))
  }
}