Add a value to Numbers spreadsheet with a web service call

I am putting together a crypto coin financial spreadsheet and one of the values I want to use is the current value of Etherium which I can get from a simple web service call to a websites API ( https://min-api.cryptocompare.com/data/pricemulti?fsyms=ETH&tsyms=USD,USD). How to I add a function to the table to get and show the return value of this call? I know Excel has this functionality but I really don't like using Excel.

Mac OS X (10.7.5)

Posted on Mar 18, 2018 4:24 PM

Reply
3 replies

Mar 18, 2018 6:58 PM in response to Nerves82

Unlike Excel Numbers does not have UDF (user defined functions).


However, you can retrieve values from the website using a short script like the one before.


  1. Copy-paste script below into Script Editor (in Applications > Utilities folder).
  2. May sure Script Editor.app is listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility.
  3. Change the document, sheet, and table names in the first few lines to match your setup.
  4. With the document open click the 'run' button in Script Editor.


SG


set theSymb to "ETH"

set d to "MyDocumentName.numbers"

set s to "MySheetName"

set t to "MyTableName"

set tgtCell to "A1"

set theURL to "https://min-api.cryptocompare.com/data/pricemulti?fsyms=" & theSymb & "&tsyms=USD,USD"

set thePrice to do shell script "curl -s " & quoted form of theURL

set thePrice to thePrice's last word

tell application "Numbers" to tell document d's sheet s's table t

set celltgtCell'svalue to thePrice

end tell

Mar 18, 2018 7:01 PM in response to SGIII

Wow, what a great answer! This was better then I was honestly hoping for. So for this script to run, will Script Editor need to be open and run this script every time to update that value or is there a way to embed it into the spreadsheet? Ideally I would like to be able to make it update on document open or ever 90 seconds or so. Is that possible? Thanks again SGIII!

Mar 19, 2018 7:02 AM in response to Nerves82

Nerves82 wrote:


Wow, what a great answer! This was better then I was honestly hoping for. So for this script to run, will Script Editor need to be open and run this script every time to update that value or is there a way to embed it into the spreadsheet?


You can't "embed" a script into the document. But you can put it in the menu or into an "Automator Service" to which you can attach a keyboard shortcut.


There are ways to have a script run automatically at regular time intervals but I don't recommend that as it tends to get a little "clunky" and potentially interfere with other things you are doing on your computer.


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Add a value to Numbers spreadsheet with a web service call

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.