Jump to content

Snapshot api question


Not_a_good_sniper
 Share

Recommended Posts

Hello everyone! In discord server I saw an announcement that a dev released new api for searching listings on backpack tf and I decided to test it. Previously (like 3-4 months ago) I had a bot running for a week or so with an old api and it works just fine, now I made a new script which looks way better, however I found something strange about this snapshot api. Chances are it's bc of my script, but in the older bot, same method was working fine but not with this new api. There is actually a small difference, I will say about it later

The method I am using:

var promises = [];

promises.push(axios({
	url: 'https://backpack.tf/api/classifieds/listings/snapshot',
		method: 'GET',
	params: {
		token: "[REDACTED]"
	},
	data: {
		sku: "Tour of Duty Ticket",
		appid: 440
	}
}));

promises.push(axios({
	url: 'https://backpack.tf/api/classifieds/listings/snapshot',
		method: 'GET',
	params: {
		token: "[REDACTED]"
	},
	data: {
		sku: "Strange Rocket Launcher",
		appid: 440
	}
}));

promises.push(axios({
	url: 'https://backpack.tf/api/classifieds/listings/snapshot',
		method: 'GET',
	params: {
		token: "[REDACTED]"
	},
	data: {
		sku: "Strange Killstreak Rocket Launcher",
		appid: 440
	}
}));

Promise.all(promises).then(res => {
	console.log(res);
}).catch(err => {
	console.log(err);
});

My script loops trough every single item that requires price update and to be short it looks like a code above. I don't know can you actually do it this way, but it looks nice. The response is the issue - this api returns listings for other items (for example, instead of Strange Killstreak Rocket Launcher this api returns items for Strange Rocket Launcher). Response itself:

[
  {
    status: 200,
    statusText: 'OK',
    headers: {
      date: 'Sat, 08 Jan 2022 14:15:19 GMT',
      'content-length': '31467',
      connection: 'close',
      'access-control-allow-origin': '*',
      'access-control-allow-methods': 'GET, POST, DELETE, PATCH',
      'access-control-allow-headers': 'Authorization, Content-Type, X-HMAC-Timestamp, X-HMAC-Hash, X-App-Context',
      'access-control-expose-headers': 'Authorization, Content-Type, X-HMAC-Timestamp, X-HMAC-Hash, X-App-Context',
      'cf-cache-status': 'DYNAMIC',
      'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
      'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=3Zth%2BywYCb9ulDjkAxkoW0XTApx%2FOAM%2B5%2FOwfLNqeTP%2FBPR%2FrFP19IZQ2Rzmeps%2F6U0ehPrGNHWX31RxXLW80jEtJyeMqk%2BwMc6a5b5arou1MRsfh6jQra2Tcxo5"}],"group":"cf-nel","max_age":604800}',
      nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
      'strict-transport-security': 'max-age=31536000; includeSubDomains',
      server: 'cloudflare',
      'cf-ray': '6ca6098cb89e15f6-DME'
    },
    config: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      headers: [Object],
      url: 'https://backpack.tf/api/classifieds/listings/snapshot',
      method: 'get',
      params: [Object],
      data: '{"sku":"Tour of Duty Ticket","appid":440}'
    },
    request: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      _header: 'GET /api/classifieds/listings/snapshot?token=[REDACTED] HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'User-Agent: axios/0.24.0\r\n' +
        'Content-Length: 41\r\n' +
        'Host: backpack.tf\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/api/classifieds/listings/snapshot?token=[REDACTED]',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'backpack.tf',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: {
      listings: [Array],
      appid: 440,
      sku: 'Tour of Duty Ticket',
      createdAt: 1641651276
    }
  },
  {
    status: 200,
    statusText: 'OK',
    headers: {
      date: 'Sat, 08 Jan 2022 14:15:20 GMT',
      'content-length': '31467',
      connection: 'close',
      'access-control-allow-origin': '*',
      'access-control-allow-methods': 'GET, POST, DELETE, PATCH',
      'access-control-allow-headers': 'Authorization, Content-Type, X-HMAC-Timestamp, X-HMAC-Hash, X-App-Context',
      'access-control-expose-headers': 'Authorization, Content-Type, X-HMAC-Timestamp, X-HMAC-Hash, X-App-Context',
      'cf-cache-status': 'DYNAMIC',
      'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
      'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=XIMwuO63sslhamyuxT1PBFyDI0nmMwB9fLnPCdc2EYb%2Famig4otOgWgvkT4NGw%2FdVkZRir2DBQp9jpdzX3wJScCRmavXSaDKOUVXVeHqDwH74EvRjD%2B2dDh%2FcUZZ"}],"group":"cf-nel","max_age":604800}',
      nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
      'strict-transport-security': 'max-age=31536000; includeSubDomains',
      server: 'cloudflare',
      'cf-ray': '6ca6098cbe877a71-DME'
    },
    config: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      headers: [Object],
      url: 'https://backpack.tf/api/classifieds/listings/snapshot',
      method: 'get',
      params: [Object],
      data: '{"sku":"Strange Rocket Launcher","appid":440}'
    },
    request: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      _header: 'GET /api/classifieds/listings/snapshot?token=[REDACTED] HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'User-Agent: axios/0.24.0\r\n' +
        'Content-Length: 45\r\n' +
        'Host: backpack.tf\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/api/classifieds/listings/snapshot?token=[REDACTED]',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'backpack.tf',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: {
      listings: [Array],
      appid: 440,
      sku: 'Tour of Duty Ticket',
      createdAt: 1641651276
    }
  },
  {
    status: 200,
    statusText: 'OK',
    headers: {
      date: 'Sat, 08 Jan 2022 14:15:19 GMT',
      'content-length': '31467',
      connection: 'close',
      'access-control-allow-origin': '*',
      'access-control-allow-methods': 'GET, POST, DELETE, PATCH',
      'access-control-allow-headers': 'Authorization, Content-Type, X-HMAC-Timestamp, X-HMAC-Hash, X-App-Context',
      'access-control-expose-headers': 'Authorization, Content-Type, X-HMAC-Timestamp, X-HMAC-Hash, X-App-Context',
      'cf-cache-status': 'DYNAMIC',
      'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
      'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=SW6mD2TC3OgiNIcIAP7lfgY4NJxhz0CMrtYtvS4dOAZl%2BC5inghcZ3STqBPz29NVTcS%2BWmHSGJROmGH2in6Q%2FWgJC0qkrpN%2B6Oa%2BSaGhFhYTAbziIK5QrenNvCvj"}],"group":"cf-nel","max_age":604800}',
      nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
      'strict-transport-security': 'max-age=31536000; includeSubDomains',
      server: 'cloudflare',
      'cf-ray': '6ca6098cba3016c3-DME'
    },
    config: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      headers: [Object],
      url: 'https://backpack.tf/api/classifieds/listings/snapshot',
      method: 'get',
      params: [Object],
      data: '{"sku":"Strange Killstreak Rocket Launcher","appid":440}'
    },
    request: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      _header: 'GET /api/classifieds/listings/snapshot?token=[REDACTED] HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'User-Agent: axios/0.24.0\r\n' +
        'Content-Length: 56\r\n' +
        'Host: backpack.tf\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/api/classifieds/listings/snapshot?token=[REDACTED]',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'backpack.tf',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: {
      listings: [Array],
      appid: 440,
      sku: 'Tour of Duty Ticket',
      createdAt: 1641651276
    }
  }
]

Lets have a look at this response: for some unknown for me reasons, in all 'subresponses' backpack returned listings for Tour of Duty Ticket not matter what is in the config.data.sku. The only response that is fine is the first subresponse, probably because, it is first. Sometimes, response may differ.

 

Alright, what was an actual method in my old bot? Besides being a spaghetti code, it was looping trough every single item, then putting a single axios into a promise.all method and then calling it with .then(res), I don't know why I did it that way, I think it wasn't working at all if you do it the "proper" way. Anyways, I don't think that this is playing a big role here

 

Any ideas why this is happening?

Link to comment
Share on other sites

Ok I have made some researches and I think this api is broken indeed, even if you are not requesting anything but for a single item, still returns listings for other item.

Link to comment
Share on other sites

can confirm the api is working.

im not entirely sure whats wrong here but try putting something like this as a header: 

{
    "User-Agent": "myBot",
}

 

Also you need to put the data in the query (params)

Link to comment
Share on other sites

42 minutes ago, Brom127 said:

can confirm the api is working.

im not entirely sure whats wrong here but try putting something like this as a header: 

{
    "User-Agent": "myBot",
}

 

Also you need to put the data in the query (params)

Simply changing to this doesn't work

axios({
	url: 'https://backpack.tf/api/classifieds/listings/snapshot',
		method: 'GET',
	params: {
		token: "[REDACTED]"
	},
	data: {
		sku: "Strange Killstreak Rocket Launcher",
		appid: 440
	},
	header: {
		"User-Agent": "myBot"
	}
})

Or I am supposed to replace something with something?

Anyways if this what you are trying to tell, can you give me an example of a code which works bc I have no idea why it's not working when it should work. Like legit what's wrong

Link to comment
Share on other sites

47 minutes ago, Zeus_Junior said:

For get requests you should use `params`. Not `data`. See if that fixes anything

https://www.npmjs.com/package/axios#request-config

Yep it worked, big thanks. Thank you for the help, again. I wasn't reading fully these docs and now I get it. Damn I should really start reading things entirely

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...