Skip to content
TORNLIFE More

Google Spreadsheet - API

Started by AAW [1525734] on in API Development.

19 replies · 2.53k views · thread synced · 4 days ago · View on torn.com
About this thread

Posts archived: 20 / 20 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
20
Discussion span
→
People posting
11
Likes on archived posts
43
Posts by staff, officers and moderators
2
Authority score
75 / 100
Historical score
44 / 100
Story score
54 / 100
Engagement score
74 / 100
AAW [1525734]

Seen someone posting about how can they implement Torn's API System into a Google Spreadsheet?

Here's your answer!

Step 1: (If you already have a google spreadsheet setup then ignore this part) Create a new Spreadsheet!

Step 2: Click on Tools and select "Script Editor"

Step 3: Click File > New > Script File

Step 4: Remove all data in the script file!

Step 5: Insert this code (http://pastebin.com/raw.php?i=FrZfx0qA)

Step 6: Rename the script JSON.gs and Save the file!

Step 7: Go back too your Spreadsheet and you can now use the parameter =importJSON

Parameter: =importJSON("APILINK", "/name", "noInherit, noTruncate")

Example 1: =importJSON("

http://api.torn.com/user/?selections=profile&key={APIKEYHERE}", "/name", "noInherit, noTruncate")

Returns the Name

Example 2: =importJSON("http://api.torn.com/user/?selections=profile&key={APIKEYHERE}", "/rank", "noInherit, noTruncate")

Returns the Rank


[image: i66.tinypic.com]

Topolino [12004]

Hi AAW

Nice intro to get people started with this.

However, I think you need to use the parameter =ImportJSON when using the code you posted

Tops
IceBlueFire [776] Officer Officer

I'm not familiar with JSON in spreadsheets, but is this making a request per field that is using it? Or is it making one request and then referencing stored data somehow? If the first one, you're gonna have to be incredibly careful with it.
AAW [1525734]

yeah thats the only hard bit about it :/ Google Spreadsheets can only use 100 Cells a minute without errors
Topolino [12004]

The way around this would be to use one page/tab of the spreadsheet to dump all variables from a particular selection and then a second tab to display the info as you want it

For example, you could use =ImportJSON(http://api.torn.com/user/?selections=profile&key={APIKEYHERE}")

This will then dump all the User/profile variables into the page in one call and help avoid hitting the request limit

Then use a second spreadsheet tab to display what you want

Not exactly elegant, but it should work


Topolino [12004]

The script already refreshes all data automatically upon opening the spreadsheet

If you want to just click one button and update manually all the data, then you can do the following

In the top menu bar there should be a menu that says "Script Center Menu"

In here should be the option "Read Data"

This should refresh all data, although I guess you would consider this manually updating

I guess it depends how often you want to update it?
Fuzzywazzy [1608900]

How would someone pull the lowest bazaar/item market price from the item market link?

I can also see it being feasible from the inventory link because of the RP stated at the end of each item's data.
Fuzzywazzy [1608900]

How would I limit the function to only output the first entry? I want to pull multiple items at the same time, but I want to avoid having like 10 sheets in the same workbook.
Mr_PotatoHead [1562191]

Sorry for the noob question, as I am very new to all this api stuff.

Can something like this be done but for excel?

I've seen people build spreadsheets for EVE Online in excel using api links and import data from web, however when I try this for the Torn API it just asks me to save it as a JSON.

Is there a simple way of doing it? Or shall I just leave it well alone?
Yukio [906148]

It's not really the simplest task, however it is possible.
I am currently working on a company employee stat helper and it's based 100% in Excel.


Winged_Cougar [1993598]

I've got this working with pricing data, which is exactly what I wanted. Thanks for that. :)

In an effort to reduce the data imported, just to clean things up a bit, is there a way to import only the first(and therefore lowest) item price, and simply not include any further data in the imported array? This isn't even strictly necessary, more of a curiosity for me. Thanks in advance. Nevermind, I see someone has already asked that, and the answer is no simple way.

I should probably also add that I can't get "noHeaders" to work...

This works:
=importJSON("https://api.torn.com/market/258?selections=&key=APIKEY)

This doesn't:
=importJSON("https://api.torn.com/market/258?selections=&key=APIKEY", "noHeaders")

Nor does this:
=importJSON("https://api.torn.com/market/258?selections=&key=APIKEY", "rawHeaders,noHeaders")
BeefcakeRage [1976144]

Any idea what API link you can use which will show only the cheapest of say item 258 rather than showing all the listings?

Also is there a way using =importJSON("https://api.torn.com/user/1976144?selections=personalstats&key=APIKEY") that rather than it all going across in columns to have it going down in rows?
Winged_Cougar [1993598]

Beefcake, what I did to get only the cheapest item was to just load the item info into an entirely different sheet, and then just reference that first cell, with the cheapest price in it from whichever sheet I needed to have the info in. Works just fine.

I'm still looking for a way to use this to import current stock prices. I get an error when using it with the "Torn" API option(shown at the bottom of the API "try it!" page), with "stocks" as the selection.

Also, on a slightly off topic note: does anyone know of a way to pull item prices from other countries? Drugs, specifically. Is there even a way to do that with the API? Is there a way to do it with a different API? Does travelrun have an API?(heard a rumor that it did, but haven't seen one anywhere yet)
Winged_Cougar [1993598]

Mine is mysteriously broken today after months of functionality. Anyone know if something got changed on the back end?



I figured it out. I left my sheet open too long and it got borked up. Close, reopened, good to go.