Axle Change Posted August 7, 2017 Share Posted August 7, 2017 Was looking at https://forums.backpack.tf/index.php?/topic/50834-api-to-remove-listings/ Just to recap on fiskie's response a year ago: GET /api/classifieds/v1/_search (same parameters as regular classifieds web client search) //https://backpack.tf/api/docs/classifieds_search POST /api/classifieds/v1/_pulse (supersedes the Automatic heartbeat, lets everyone know you're "alive", bumps all listings, etc) //We still have to do this with heartbeat https://backpack.tf/api/docs/auxiliary PUT /api/classifieds/v1/listing (item body or item id depending on intent, sell order or buy order) //https://backpack.tf/api/docs/create_listings GET /api/classifieds/v1/listing/{id} //We don't have a way to get a specific listing. We have to do https://backpack.tf/api/docs/my_listings then parse the response which is fine. DELETE /api/classifieds/v1/listing/{id} //This functionality is completely missing and cannot be done through the provided API. Fiskie pls Link to comment Share on other sites More sharing options...
A Delicious Cashew Posted August 7, 2017 Share Posted August 7, 2017 http://imgur.com/a/R5WdX from a few days ago on discord Axle Change 1 Link to comment Share on other sites More sharing options...
pewpewAttack Posted August 7, 2017 Share Posted August 7, 2017 were you guys able to get it to work? var data = JSON.stringify({listing_ids : [{id : "440_6013671119"}, {id : "440_5989064097"}]}); request.delete('https://backpack.tf/api/classifieds/delete/v1?key=MYKEYGETUROWN',{ body : data },function(err,response,body){ if(err) console.log(err); else{ var data = JSON.parse(response.body); console.log(data); } }); This is my response that I get. { deleted: 0, errors: [] } Am I missing something? If you have gotten it to work please share. Maybe the listing id's are invalid? idk. Link to comment Share on other sites More sharing options...
pewpewAttack Posted August 7, 2017 Share Posted August 7, 2017 var data = JSON.stringify({listing_ids : [{id : '440_6013671119'}, {id : '440_5989064097'}]}); request.delete('https://backpack.tf/api/classifieds/delete/v1?key=MYKEYGETUROWN',{ headers : {"Content-Type": "application/json"}, body : data },function(err,response,body){ if(err) console.log(err); else{ var data = JSON.parse(response.body); console.log(data); } }); Added headers now the response is: { deleted: 0, errors: [ { listing_id: [Object], message: 'This listing does not exist.' }, { listing_id: [Object], message: 'This listing does not exist.' } ] } Link to comment Share on other sites More sharing options...
Axle Change Posted August 7, 2017 Author Share Posted August 7, 2017 1 hour ago, pewpewAttack said: -snip- It seems to require cookies: var request = require('request'); var headers = { 'content-type': 'application/json', }; var data= '{"listing_ids": [ "440_5730888796", "440_5739645534" ] }'; var options = { url: 'https://backpack.tf/api/classifieds/delete/v1?key=MUHKEY', method: 'DELETE', headers: headers, body: data }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } else{ console.log(error); console.log(body); } } request(options, callback); This returns {"deleted":0,"errors":[{"listing_id":"440_5730888796","message":"This listing does not belong to you."},{"listing_id":"440_5739645534","message":"This listing does not exist."}]} Also the JSON you were posting was incorrectly formatted, listing_ids needs to be in quotes and there are no sub-names. EDIT: It works if you fake the cookies, but this takes away the entire point of having an API in the first place. Link to comment Share on other sites More sharing options...
Axle Change Posted August 7, 2017 Author Share Posted August 7, 2017 2 hours ago, pewpewAttack said: snip FML, just spent a few hours when I finally realized the problem. You HAVE to use https://backpack.tf/api/classifieds/delete/v1?token=yourtoken The TOKEN is https://backpack.tf/settings##advanced NOT https://backpack.tf/api/register Just to put it all together, this works: var request = require('request'); var headers = { 'content-type': 'application/json', }; var data= '{"listing_ids": [ "440_5730888796", "440_5739645534" ] }'; var options = { url: 'https://backpack.tf/api/classifieds/delete/v1?token=yourTOKENonhttps://backpack.tf/settings', method: 'DELETE', headers: headers, body: data }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } else{ console.log(error); console.log(body); } } request(options, callback); I completely forgot there was a difference between token and api key. fuckity fuck fuck Link to comment Share on other sites More sharing options...
pewpewAttack Posted August 8, 2017 Share Posted August 8, 2017 var data = JSON.stringify({listing_ids : ['440_5126438655','440_5989064097']}); request.delete('https://backpack.tf/api/classifieds/delete/v1?token=MYTOKENUSEUROWN',{ headers : {"Content-Type": "application/json"}, body : data },function(err,response,body){ if(err) console.log(err); else{ var data = JSON.parse(response.body); console.log(data); } }); Thanks Axle Change, the above code is tested to work now. Response I get back { deleted: 2, errors: [] }; Also to get ur token use this url : https://backpack.tf/settings##advanced Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now