Search code examples
javascriptsteam

Error with Typescript Axios - 400 bad Request


I am currently encountering an unusual problem with my request in Javascript / typescript. I keep getting a 400 bad request back, but I think my request should be correct.

My Code looks like this:

import axios from "axios";

let market_name: string = "★ M9 Bayonet | Marble Fade (Factory New)";

// Axios-Instanz erstellen

const instance = axios.create({
  baseURL: "https://steamcommunity.com/market/pricehistory/",
  //pretier-ignore
  headers: {
    "Cookie": "sessionid=XXX; steamLoginSecure=76XXXXXXXXXXXHzCA", 
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36",
    "Accept": "application/json, text/plain, */*",
    "Accept-Encoding": "gzip, deflate, br",
    "Connection": "keep-alive"
  },
  params: {
    "appid": "730", // Steam App-ID für CS:GO
    "market_hash_name": market_name, // Marktname des Artikels, der als Parameter übergeben wird
  }
});

instance.get()
  .then((response) => {
    console.log("Respone from API:", response.data);
  })
  .catch((error) => {
    console.error("Error", error);
  });

After running the JS File the request is also correctly URL encoded:

https://steamcommunity.com/market/pricehistory/?appid=730&market_hash_name=%E2%98%85+M9+Bayonet+%7C+Marble+Fade+(Factory+New)

With the valid cookie (very important, otherwise its not working), the request should actually be possible and works for me in the browser as well as in python (requests) without any problems.

I get the following Response/Error:

[]
{
  transitional: {
    silentJSONParsing: true,
    forcedJSONParsing: true,
    clarifyTimeoutError: false
  },
  adapter: [ 'xhr', 'http', 'fetch' ],
  transformRequest: [ [Function: transformRequest] ],
  transformResponse: [ [Function: transformResponse] ],
  timeout: 0,
  xsrfCookieName: 'XSRF-TOKEN',
  xsrfHeaderName: 'X-XSRF-TOKEN',
  maxContentLength: -1,
  maxBodyLength: -1,
  env: {
    FormData: [Function: FormData] {
      LINE_BREAK: '\r\n',
      DEFAULT_CONTENT_TYPE: 'application/octet-stream'
    },
    Blob: [class Blob]
  },
  validateStatus: [Function: validateStatus],
  headers: Object [AxiosHeaders] {
    Accept: 'application/json, text/plain, */*',
    'Content-Type': undefined,
    Cookie: 'sessionid=XXXX; steamLoginSecure=XXXA',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
    'Accept-Encoding': 'gzip, deflate, br',
    Connection: 'keep-alive'
  },
  baseURL: 'https://steamcommunity.com/market/pricehistory/',
  params: {
    appid: '730',
    market_hash_name: '★ M9 Bayonet | Marble Fade (Factory New)'
  },
  method: 'get',
  data: undefined
}

Do you have any ideas?


Solution

  • I don't have a specific solution though: after leaving the script for a few days and trying it today with the same code, it worked. If you encounter such problems: It may well be that the error lies with Steam, or that the Steam servers are blocking your script. Try it a day later with a different ip and new cookie data etc.