Google Spreadsheet Code Example

Using the awesome ImportJSON tool in combination with this wonderful script, you are able to get the GuruFocus API data into a google spreadsheet in a matter of minutes. Here’s how:

  1. Create a new Google Spreadsheet.
  2. Click on Extensions -> Apps Script.
  3. Click the "+" button in the Files category to create a new script file.
  4. Delete the placeholder content and paste the code from this script.
  5. Rename the script to ImportJSON.gs and click the save button.
  6. Back in the spreadsheet, in a cell, you can type “=ImportJSON()” and begin filling out it’s parameters.

For example, if you want to use GuruFocus API to get valuation ratios in Google Spreadsheet, just try the following function in your spreadsheet

=ImportJSON(("https://api.gurufocus.com/public/user/{api_token}/stock/AAPL/keyratios"), "/Valuation", "")

The output will be:

Output

If you encounter an error with the message "Result was not automatically expanded, please insert more columns". Please use the TRANSPOSE function to change the row and column indices of the result.

        =TRANSPOSE( ImportJSON(("https://api.gurufocus.com/public/user/{api_token}/stock/WMT/financials")) )
      

The ImportJSON script limited the number of characters in a cell to 256. You can change that in the function defaultTransform_ of the script.