Giter Site home page Giter Site logo

Comments (1)

qeet avatar qeet commented on May 22, 2024 1

In theory you should just be able to call IMPORTJSONAPI from the onOpen trigger so that the import is run everytime you open the sheet:

function onOpen(e) {
  // Code to import data and update spreadsheet
  ...
}

However there is a problem with this in that the IMPORTJSONAPI makes an external network request which is not allowed from a script called by the onOpen trigger. A better explanation is provided here:

https://stackoverflow.com/questions/55996556/google-apps-script-urlfetchapp-permission

The second option is to add a button to your spreadsheet which does the import when you manually click the button. To do this add the following function to your script:

function UPDATE_DATA() {
  var ROW = 1
  var COL = 1
  var values = IMPORTJSONAPI("http://data.nba.net/10s/prod/v1/2018/teams.json", "$.league.*[*]", "^.~, city, isNBAFranchise")
  var numrows = values.length
  var numcols = values[0].length
  SpreadsheetApp.getActiveSheet().getRange(ROW, COL, numrows, numcols).setValues(values) 
}

You will need to change the ROW and COL to where you want to insert the data and also update the IMPORTJSONAPI arguments to your own. Now read the following tuturial which describes how you add a button to your spreadsheet and hook it up to the above function:

https://www.benlcollins.com/apps-script/google-sheets-button/

Hope this helps.

from importjsonapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.