Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
¿Por qué fetch no funciona correctamente con Google Apps Script?

He estado tratando de modificar un valor relacionado con un artículo utilizando la API de una tienda y, aunque devuelve el éxito, el objeto sin raw no trae los valores correctamente y no puedo averiguar por qué.

Los registros del Editor de secuencias de comandos muestran: Raw data: {"tipo":3,"quantidade":10} ...que es correcto.

La respuesta que obtengo es: "code":"010","message":"success","responseCode":200,

El registro de destino muestra: {"erp_id":"","peso":"","gtin":"","ativo":"","tipo":"","quantidade":"", .. .donde tipo y quantidade están vacíos, por lo tanto, incorrectos.

Aquí está la pieza de código en la que estoy trabajando:

 function addToStock() { try { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheetByName('Estoque PA'); const id = sheet.getRange(2, 3).getValue(); let quantidade = sheet.getRange(2, 5).getValue(); const variacao = sheet.getRange(2, 6).getValue(); const raw = JSON.stringify({ 'tipo': 3, 'quantidade': quantidade }); const headers = { 'Content-Type': 'application/json', 'Authorization': "Bearer " + API_KEY }; const requestOptions = { "method": 'PUT', "headers": headers, "body": raw, "redirect": 'follow' }; Logger.log('Raw data: ' + raw) const url = `https://api.wwwww.com.br/v1/product/stock/${id}/${variacao}`; Logger.log('URL: ' + url) const response = UrlFetchApp.fetch(url, requestOptions); const getText = response.getContentText(); Logger.log('GetText: ' + getText); } catch (err) { Logger.log('Error: ' + err) } }

¿Alguna idea de por qué los datos sin procesar no se procesan por completo?

¡Gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En las opciones de UrlFetchApp , el cuerpo de la solicitud se indica mediante la payload en lugar del body :

 const requestOptions = { "method": 'PUT', "headers": headers, "payload": raw, // change this line 'followRedirects': true // and this one };

Referencia: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetch(Cadena,Objeto)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!