Jump to content

Issues with the API


escept

Recommended Posts

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"

Link to comment
Share on other sites

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").

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

  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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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;
}

Link to comment
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.
×
×
  • Create New...