Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Download File using API Call in AppsScript

I'm trying to generate an invoice using data from my spreadsheet, and I'm not very familiar with HTTPS requests, let alone Google's UrlFetchApp. I'm trying to convert this example code provided by the API into something that AppsScript can use. So far it just saves the website as a .html to the folder.

function debug(){
  run();
}

const folderName = 'Invoices Test'

function generateInvoice(invoice) {
    var postData = JSON.stringify(invoice);
    var options = {
      'method'    : "post",
      'contentType': "application/json",
      'payload': postData
    };

    // Make a POST request with a JSON payload.
    var response = UrlFetchApp.fetch('invoice-generator.com', options);
    var fileBlob = response.getBlob();
    var folderID = getInvoiceFolderID();
    var folder = DriveApp.getFolderById(folderID);
    var result = folder.createFile(fileBlob);
}

/**
 * @return String
 */
function getInvoiceFolderID(){
  var id;

  var folders = DriveApp.getFoldersByName(folderName);
  if(!folders.hasNext()){
    DriveApp.createFolder(folderName).getId();
  }
  else{
    id = folders.next().getId()
  }
  return id;
}

var invoice = {
    logo: "http://invoiced.com/img/logo-invoice.png",
    from: "Invoiced\n701 Brazos St\nAustin, TX 78748",
    to: "Johnny Appleseed",
    currency: "usd",
    number: "INV-0001",
    payment_terms: "Auto-Billed - Do Not Pay",
    items: [
        {
            name: "Subscription to Starter",
            quantity: 1,
            unit_cost: 50
        }
    ],
    fields: {
        tax: "%"
    },
    tax: 5,
    notes: "Thanks for being an awesome customer!",
    terms: "No need to submit payment. You will be auto-billed for this invoice."
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use the full link in the UrlFetchApp.fetch parameter, as follows:

var response = UrlFetchApp.fetch('https://invoice-generator.com', options);

This would return the correct response as a PDF:

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda