Axios created string returns 403 forbidden since the URL is broken when the URL is made by combining several strings.
Here is an example: This works fine:
const inventory = await axios.get("http://steamcommunity.com/inventory/76561198164672016/730/2?l=english&count=5000");
It returns the correct results.
But when using the same URL, just combining different values, it does not work.
const testId = 76561198164672016;
const path = "http://steamcommunity.com/inventory/"+testId.toString()+"/730/2?l=english&count=5000"
const inventoryWithPath = await axios.get(path);
This returns an error. I don't understand how this can happen when the strings are the same... Here is the full code.
const axios = require('axios').default;
const testId = 76561198164672016;
async function getInventory(){
try{
//invetory works fine and returns correct values
const inventory = await axios.get("http://steamcommunity.com/inventory/76561198164672016/730/2?l=english&count=5000");
//Even though this has the same URL it returns an error. Why and how can I request based on the path?
const path = "http://steamcommunity.com/inventory/"+testId.toString()+"/730/2?l=english&count=5000"
const inventoryWithPath = await axios.get(path);
//console.log(inventoryWithPath)
console.log(inventory)
return inventory;
}
catch(err){
console.log(err);
console.log("Error happened")
}
}
module.exports={getInventory}
As suggested in the comments, the reason your code isn't working is because testId > Number.MAX_SAFE_INTEGER. What you can do to solve this is use BigInt like this:
const path = "http://steamcommunity.com/inventory/" + BigInt(testId).toString() + "/730/2?l=english&count=5000"