Jump to content
escept

Issues with the API

Recommended Posts

escept    0
escept

Hello, For me the Create listings API is not informative as i'm really new to JSON and other kinds of stuff. Sending a JSON post request to create a new listing does not seem to work. My Code: {"token":"xxxxxxxxxxxxxxxxxxxxxxxxx","listings":["intent":"1","id":"30310","offers":"1","buyout":"1","details":"test","currencies":["metal":10]]}", The link: "https://backpack.tf/api/classifieds/list/v1"

Share this post


Link to post
Share on other sites
Julia    813
Julia

The listing JSON should be formatted like this:

{
   "listings":[
      {
         "intent":1,
         "id":5986406778,
         "currencies":{
            "keys":8
         },
         "details":"With Headshot Kills",
         "buyout":1,
         "offers":1,
         "promoted":0
      }
   ]
}

 

Your JSON is not properly formatted (and isn't valid JSON either). "listings" is an array of objects, and "currencies" is an object ("metal" and/or "keys").

Share this post


Link to post
Share on other sites
Axle Change    48
Axle Change
30 minutes ago, escept said:

-snip-

Edit your post please, you included your api token on the url.

Error 400 probably means you probably didn't set your headers or sent an invalid object. You should probably send it as a string because it makes life much easier.

Set headers to 'content-type': 'application/json'

Share this post


Link to post
Share on other sites
escept    0
escept
  1. As i said, i'm pretty new to json, and programming altogether, i don't really know what you meant by that. I'm trying to make this in vb.net and my code is 
        Dim jsonszar As String
        jsonszar = "
        {
        ""content-type"":""application/json""
        ""token"":""-""
         ""listings"":[
            {
               ""intent"":1,
                ""id"":30797,
               ""currencies"":{
                  ""metal"":1
              },
              ""details"":""test"",
              ""buyout"":1,
              ""offers"":1,
               ""promoted"":0
            }
        ]
        }
        "
        Dim myrequest As HttpWebRequest = postjson(jsonszar, "https://backpack.tf/api/classifieds/list/v1")

I'm sorry for everyone who i'm nerve-racking for..

Share this post


Link to post
Share on other sites
pewpewAttack    25
pewpewAttack

I think ur using the wrong id. ur id is only 5 in length in the example Julia gave its 10.

Share this post


Link to post
Share on other sites
manic    2
manic
3 minutes ago, escept said:

Where should i get the id from then?

You should use the 3rd party access token: https://backpack.tf/settings##advanced . And you posted your key again.

Edit: rip, read token not id. The id is the current id which you can get from using the steam inventory API.

Share this post


Link to post
Share on other sites
escept    0
escept

Not that, the item id. Oh and sorry i did not notice that one.

Share this post


Link to post
Share on other sites
pewpewAttack    25
pewpewAttack

you would need to use the steam inventory api or if you just want to test it out now https://backpack.tf/item/4083557913, For a test , this item has an id of 5622776387 you can try that for now.(btw this is ur item that u own)

Share this post


Link to post
Share on other sites
escept    0
escept

still not working... i think now it's the code itself that has problems..

Share this post


Link to post
Share on other sites
Julia    813
Julia
2 hours ago, escept said:
  1. As i said, i'm pretty new to json, and programming altogether, i don't really know what you meant by that. I'm trying to make this in vb.net and my code is 

        Dim jsonszar As String
        jsonszar = "
        {
        ""content-type"":""application/json""
        ""token"":""-""
         ""listings"":[
            {
               ""intent"":1,
                ""id"":30797,
               ""currencies"":{
                  ""metal"":1
              },
              ""details"":""test"",
              ""buyout"":1,
              ""offers"":1,
               ""promoted"":0
            }
        ]
        }
        "
        Dim myrequest As HttpWebRequest = postjson(jsonszar, "https://backpack.tf/api/classifieds/list/v1")

I'm sorry for everyone who i'm nerve-racking for..

You don't add the "content-type" in the POST data, it belongs in the request headers. You should have a basic understanding of how web requests work. The request method should be POST and any JSON should be the "form" of your request. You should look up some examples of a properly formatted POST request. Also I noticed recently that backpack.tf gives errors if you try to view any page without a user-agent in the request. 

 

If there is something wrong with your post data backpack.tf will usually return JSON that includes an error message. If there is a problem with your request you won't get a proper response. If your JSON is not properly formatted it might cause an error too.

 

So in your request headers you should have something like:

{
   "Content-Type":"application/json",
   "User-Agent":"someuseragent"
}

Setting the content-type to application/json tells the server that you're sending JSON.

 

1 hour ago, pewpewAttack said:

I think ur using the wrong id. ur id is only 5 in length in the example Julia gave its 10.

The ID is the ID of the item you want to sell.

Share this post


Link to post
Share on other sites
escept    0
escept

Okay so now i got the JSON itself, but I tried like 10 examples of POSTing JSON with vb.net, But none of them worked.

Share this post


Link to post
Share on other sites
manic    2
manic
50 minutes ago, escept said:

Okay so now i got the JSON itself, but I tried like 10 examples of POSTing JSON with vb.net, But none of them worked.

Does this way of doing it work with the other APIs? (mainly the GET ones)

Share this post


Link to post
Share on other sites
manic    2
manic
1 minute ago, escept said:

Actually i only tried the POST ones.

Try that, they're easier. You can see if you've messed up the syntax and response handing or if it's something else.

Share this post


Link to post
Share on other sites
escept    0
escept

Actually i have been trying with get requests too but i still can't parse the output... trying for 2 hours now..

Why is just getting a value so hard?

Share this post


Link to post
Share on other sites
escept    0
escept

Well i'm making progress, sending to https://backpack.tf/api/classifieds/list/v1

 

JSON:

{'token': 'hidden', 'listings': [{'intent': 1, 'id': 5622776387, 'currencies': { 'metal':1 }, 'details': 'test', 'buyout': 1, 'offers': 1, 'promoted': 0 }]}}

Headers:

    'User-Agent':       'Super Agent/0.0.1',
    'Content-Type':     'application/json'

 

And in response i'm getting 

500: Internal Server Error

And by the looks of it the website code itself.

Share this post


Link to post
Share on other sites
Axle Change    48
Axle Change
9 hours ago, escept said:

-snip-

Can confirm 500 error. Seems to be an error with the site as far as I can tell, only thrown with sell =1. 

Share this post


Link to post
Share on other sites
escept    0
escept

oh ok, btw i tried NodeJS instead of vb.net as it looked impossible to do post requests

Share this post


Link to post
Share on other sites
escept    0
escept

with the buy request i get a response: 

{"listings":{"Showstopper":{"error":7,"used":0,"cap":0}}}

Any item that i try to create an order for returns this...

Share this post


Link to post
Share on other sites
manic    2
manic
5 hours ago, escept said:

with the buy request i get a response: 


{"listings":{"Showstopper":{"error":7,"used":0,"cap":0}}}

Any item that i try to create an order for returns this...

You need to use your third party access token not your API key. (backpack - settings - advanced)

Share this post


Link to post
Share on other sites
pewpewAttack    25
pewpewAttack
6 hours ago, escept said:

with the buy request i get a response: 


{"listings":{"Showstopper":{"error":7,"used":0,"cap":0}}}

Any item that i try to create an order for returns this...

It literally tells you in the documentation what the problem is. You have an error code 7 which if you look at the list of error codes tells you this,

enum {
    OK = 0;
    ItemNotInInventory = 1;
    InvalidItem = 2;
    ItemNotListable = 3;
    ItemNotTradable = 4;
    MarketplaceItemNotPriced = 5;
    RelistTimeout = 6;
    ListingCapExceeded = 7;
    CurrenciesNotSpecified = 8;
    CyclicCurrency = 9;
    PriceNotSpecified = 10;
    UnknownIntent = 11;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

×