Skip to content
TORNLIFE More

Struggling the API

Started by LonelyAmanda [2601198] on in API Development.

11 replies · 155 views · thread synced · 7 days ago · View on torn.com
About this thread

Posts archived: 12 / 12 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
12
Discussion span
→
People posting
6
Likes on archived posts
2
Authority score
52 / 100
Historical score
24 / 100
Story score
30 / 100
Engagement score
55 / 100
LonelyAmanda [2601198]

Hello

 

I'm a total newbie and I'm trying to use AI to help me learn some python scripting. 

 

I'm trying to export some prices from the market and I keeping getting the error that my API doesn't have high enough permissions. I'm using full access, how do I get higher permissions or do I need a different script?

 

Sorry if this is in the wrong place 

LonelyAmanda [2601198]

I will try to produce the error soon. 

 

But in the meantime, is there a way to increase the permissions of the API beyond "full access" and I'm getting a bit confused about version 1 and 2

Omanpx [1906686]

For market stuff, you usually need a public key. The error you are getting is likely due to you using an incorrect api call. What call exactly are you making (just remove your api key)?

LonelyAmanda [2601198]

I've tried a few options with AI.

 

def fetch_market_data(item_id):

    url = f"https://api.torn.com/v2/market/{item_id}/itemmarket?offset=0"

    headers = {

        "accept": "application/json",

        "Authorization": f"ApiKey {API_KEY}"

    }

    

ChatGPT [1762864]

This is a function definition and item_id is the function argument. It gets plugged in when they make the function call, i.e. fetch_market_data(21) would sub 21 in for the ID in the URL.

 

This should work perfectly fine assuming they actually defined API_KEY, and then did the correct thing when making the request, which isn't shown in the incomplete snippet that they have posted here.

 

[image: i.imgur.com]

 

[image: i.imgur.com]

shaixi [3105871]

As this is an older post you have probably already worked it out but this is similar to what I use but with V1 

 

Using VS Code you need both 

pip install gspread oauth2client requests

pip install tabulate

 

----------------------------------------------------------------------------------------------

 

import requests

from tabulate import tabulate


def pull_flying_item_prices():

    # Insert your Torn API key directly here or prompt for it

    api_key = "KEY"  # Replace with your actual API key


    # Torn API URL

    url = f"https://api.torn.com/torn/?selections=items&key={api_key}"

    response = requests.get(url)

    data = response.json()


    items = data.get("items", {})


    # Relevant item IDs

    flying_item_ids = [

        282, 617, 271, 277, 263, 260, 272, 267, 264, 276, 385,  # Flowers

        384, 273, 258, 215, 281, 269, 266, 274, 268, 186, 618, 187, 261,  # Plushies

        206  # Xanax

    ]


    # Prepare data for printing

    output = []

    for item_id in flying_item_ids:

        item = items.get(str(item_id))

        if item:

            output.append([item["name"], item_id, f"${item['market_value']:,}"])


    # Print table

    print(tabulate(output, headers=["Item Name", "Item ID", "Market Value ($)"], tablefmt="pretty"))


# Run the function

pull_flying_item_prices()

 

-----------------------------------------------------------------------------------------------------

 

To change to what items you want just change IDs hope this helped

It returns this:

 

 

+--------------------+---------+------------------+
|     Item Name      | Item ID | Market Value ($) |
+--------------------+---------+------------------+
|   African Violet   |   282   |     $54,084      |
|   Banana Orchid    |   617   |      $8,021      |
|    Ceibo Flower    |   271   |     $27,404      |
|   Cherry Blossom   |   277   |     $45,843      |
|       Crocus       |   263   |      $5,395      |
|       Dahlia       |   260   |      $1,826      |
|     Edelweiss      |   272   |      $2,042      |
|      Heather       |   267   |     $35,129      |
|       Orchid       |   264   |     $14,685      |
|       Peony        |   276   |     $54,765      |
| Tribulus Omanense  |   385   |     $61,837      |
|   Camel Plushie    |   384   |     $72,474      |
|  Chamois Plushie   |   273   |      $6,415      |
|   Jaguar Plushie   |   258   |     $14,417      |
|   Kitten Plushie   |   215   |       $617       |
|    Lion Plushie    |   281   |     $57,085      |
|   Kitten Plushie   |   215   |       $617       |
|   Kitten Plushie   |   215   |       $617       |
|   Kitten Plushie   |   215   |       $617       |
|    Lion Plushie    |   281   |     $57,085      |
|   Monkey Plushie   |   269   |     $33,273      |
|   Nessie Plushie   |   266   |     $30,006      |
|   Panda Plushie    |   274   |     $51,649      |
|  Red Fox Plushie   |   268   |     $31,882      |
|   Sheep Plushie    |   186   |       $599       |
|  Stingray Plushie  |   618   |      $6,135      |
| Teddy Bear Plushie |   187   |       $608       |
| Wolverine Plushie  |   261   |      $6,212      |
|       Xanax        |   206   |     $841,177     |
+--------------------+---------+------------------+

 

Brokenleg [3070810]

I'm kind of in the same boat. In fact I came on here to find out why I can find my API so I could reinstall FF scouter version 2 because it hasn't worked on my torn PDA and over a year. However, I didn't see it and was a little puzzled while it had disappeared. I'm a beginner to coding so I thought I would just give it a shot and read through everything however this was a pivotal mistake. I have so many questions and haven't answered one single thing. First, can somebody let me know exactly what direction I should be going into figure out this issue with FF scouter. I asked a couple of months ago and nobody helped. Also can somebody give me an update on what happened to the API and how are we supposed to get them now. Also, because of my flat out ignorance in the subject matter I would love somebody to point me into the direction for me to actually start learning the language. I feel like I'm at a huge disadvantage and would honestly have been super procrastinating about learning coding. I think this would be great position to be in and everybody on here is always helpful. So please if you wouldn't mind helping me out that would be amazing with all the questions. Hopefully I can start studying right away and actually learn something and maybe even build something especially after I figure out where the frack my API has gone. Thanks

ChatGPT [1762864]

The original FF scouter dev intentionally got themself fedded. Weav3r took over development: https://www.torn.com/forums.php#/p=threads&f=67&t=16468567&b=0&a=0 For PDA, you must ensure that you register with the same key that you use as your PDA key. 

 

"However, I didn't see it and was a little puzzled while it had disappeared." Are you saying that your API key disappeared? Your API keys should be visible at https://www.torn.com/preferences.php#tab=api and an option to make new ones will also be there. To check what key you use in PDA, open the app and click the menu bar in the top left, then settings, then click on the "TORN API USER LOADED" section at the very top.

 

"Also, because of my flat out ignorance in the subject matter I would love somebody to point me into the direction for me to actually start learning the language." What do you mean, do you mean learning the API queries? The documentation over at https://www.torn.com/swagger.php is the best place to start, and the try it functionality will tell you the URLs that it is using for each of the queries that you select. Putting those URLs into a browser and hitting enter would get you the response, but most people are using the API programmatically alongside a programming language. There is a very wide variety of languages that could be used.

Mentions: [Script] FF Scouter + RW Monitor