Jump to content

Issues with the API


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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...