Jump to content

Archived

This topic is now archived and is closed to further replies.

klenium

backpack.tf API

Recommended Posts

klenium

I tried to use backpack.tf api on my website. I want to get the player's backpack value with Javascript. But when I tried to use this simple code in console (Chrome):

$.get("http://backpack.tf/api/IGetUsers/v2/?steamids=76561198045802942");
then I only got this error message:
XMLHttpRequest cannot load http://backpack.tf/api/IGetUsers/v2/?steamids=76561198045802942. Origin http://mywebsite.com is not allowed by Access-Control-Allow-Origin.

So, how can I use this api? Do I need an api key, like "IGetPrices"? What did I do wrong?

Share this post


Link to post
Share on other sites
n0:name

 

Origin http://mywebsite.com is not allowed by Access-Control-Allow-Origin.

 

It's already there.... you can't load XML Files from other Websites than your own, it's a security thing.

Nothing you can change about it.

Share this post


Link to post
Share on other sites
klenium

But then why is there this api...? I think, everyone can use it from his website.. If I can't get these informations from my website, then what can I do? :D There's a search field, if you just want to find someone from this (backpack.tf) site.

Share this post


Link to post
Share on other sites
Brad Pitt

Your server-side script should load that, not the client - it's a browser security feature as the other person above pointed out.

Share this post


Link to post
Share on other sites
klenium

Ok. I didn't see anything about it on the api's page, so I thought I can use it in browsers.

Share this post


Link to post
Share on other sites
Uranium235

Your server-side script should load that, not the client - it's a browser security feature as the other person above pointed out.

 

Didn't the API, at least v1, support JSONP? Don't remember where I read it, since it's not documented with the API description.

But since you need an API Key, I guess that feature is no longer available...

Share this post


Link to post
Share on other sites
Brad Pitt

Some of the API functions support jsonp -- but not all of them. Anyway, like I said this should be a server-side request with some caching on your end. If the person refreshes their page on their website every 5 seconds you don't want to hit the backpack.tf server every 5 seconds.

Share this post


Link to post
Share on other sites
klenium

Again me. What's wrong with the names?

backpack.tf/api/IGetPrices/v3/?key=apikey&names=1

This doesn't include the names, only the prices.

Share this post


Link to post
Share on other sites
Brad Pitt

Again me. What's wrong with the names?

backpack.tf/api/IGetPrices/v3/?key=apikey&names=1

This doesn't include the names, only the prices.

 

Should be ok now, let me know if you notice anything odd.

Share this post


Link to post
Share on other sites
klenium

Australium weapons aren't in the API. When are you going to add them? Will you add an unique quantity like 1100 for strange uncraftables?

 

And take a look at the alt_defindex. Fire Axe has it, but Bat doesn't.

Share this post


Link to post
Share on other sites
fisk

Internally, backpack.tf no longer uses item defindexes when storing price data for a few reasons:

 

  • There are a few items which appear multiple times in the schema (e.g. keys and stock weapons) and this saves on having to remap by defindex
  • Uncraftability and untradability are now stored as separate branches. It's kind of like this:
[Kritzkrieg]
    [6]
        [Tradable]
            [Craftable]
                [Priceindex] <-- used for crate series, unusual effect IDs, etc. 0 otherwise.
                     [0]
                         {price info}
            [Non-Craftable]
                [Priceindex]
                     [0]
                         {price info}
    [11]
        [...]

Ergo we won't have to use numbers like 600 or 1100 any more to signify non-craftability.

 

I will start work on IGetPrices v4 which will use this format so it gets shipped in the next update. Supporting australium stuff should also be simple.

Share this post


Link to post
Share on other sites
fisk

That was fun. This is what IGetPrices v4 will look like:

{
    "response": {
        "success": 1,
        "current_time": 1392752280,
        "items": {
            "A Brush with Death": {
                "defindex": {
                    "0": 30186
                },
                "prices": {
                    "6": {
                        "Tradable": {
                            "Craftable": {
                                "0": {
                                    "currency": "metal",
                                    "value": 4,
                                    "last_update": 1384656665,
                                    "difference": -0.165
                                }
                            }
                        }
                    }
                }
            },
            [...]

Australium support was simple. It was just commented out of v3 since the API wasn't built for it.

I just have to polish this up and make some new documentation, it'll be ready for the upcoming update.

Share this post


Link to post
Share on other sites
klenium

Bat, kukri, shovel and some other stock weapons haven't included their 2 defindexes yet, unlike others. Why? Could you add all pls?

Share this post


Link to post
Share on other sites
klenium

Only 4 more missing :D

0 - 190 - bat

20 - 207 - sticky

5 - 195 - fists

17 - 204 - syringe

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...