Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

66
Vistas
400 error "Your client has issued a malformed or illegal request." in google scripts api, no issues until changing to different google account

I have an extremely basic API made in google scripts, that I have linked to a spreadsheet. I originally made it on my home google account and everything was working fine, I had no errors, I made it on my PC at home and ran into no errors, but when I tested it on my laptop I couldn't access it. The issue was I made it on my home google account but my school email account was made so it couldn't access files or anything outside of my school system so I just copy and pasted all my code into a google script on my school account and did the same for the spreadsheet as it is for a school project. When I just input the api link like normal it works fine, however now whenever put in a query google returns "400. That’s an error. Your client has issued a malformed or illegal request. That’s all we know." This wasn't an issue before on the API I made on my home email, and all I did was copy and paste the code nothing changed, here is the code.

function  doGet(request){
  var query = request.parameter.q
  var parameters = 6;
  var sheetname = "Sheet1";
  var doc = SpreadsheetApp.openById(PropertiesService.getScriptProperties().getProperty('key'));
  var sheet = doc.getSheetByName(sheetname)
  var lastrow = sheet.getLastRow();
  var rows = [];
  var range = sheet.getRange(2,1,lastrow,parameters);
  var values = range.getValues();
  var data
  var data_return
  for(var row in values){
    rows.push([]);
    for(var col in values[row]){
      rows[row].push(values[row][col]);
    }
  }
  if(query != null){
  if(query.includes('data[')){
    data = query.replace("data[", "");
    data = data.replace("]", "")
    data_return = "data sent: " + data
    SpreadsheetApp.getActiveSheet().getRange('A17').setValue(data);
    return ContentService.createTextOutput(JSON.stringify({data_return})).setMimeType(ContentService.MimeType.JSON);
  }
  else{
    var rowstoreturn = rows.filter(a => a[0] == query)
    return ContentService.createTextOutput(JSON.stringify({rowstoreturn})).setMimeType(ContentService.MimeType.JSON);
  }}
  return ContentService.createTextOutput(JSON.stringify({rows})).setMimeType(ContentService.MimeType.JSON);
}

function setup() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
PropertiesService.getScriptProperties().setProperty("key", doc.getId());
}

The link to the api I set up with my home email is https://script.google.com/macros/s/AKfycbwvPPynR9FAkUgMejjtQE9Rqo0ayaJPbmFoaaomkjeZobgJN_x3smasjHdeSfOTkvMO/exec

I would sent the link I also made on my school account but I can't as I can only make files accessible to people in my school system. To make a query it's like a normal API right after EXEC you just put ?q= and then whatever query you want. I can't seem to find the issue is there any fix to this? Thanks! If there is anything else I need to provide please let me know.

7 months ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.