How can I input a number API as a string OR Where am I going to place toString()

Tags: , , ,



So the code im trying to send is ( “buyPrice”:11.0 ). in the site (https://api.hypixel.net/skyblock/bazaar/product?key=a8394dae-033b-4ce5-a1a1-fb773cf2386f&productId=PORK). as you can see the value inside buyPrice is not a string but a number. and now when I send the command into discord it says “undefined”. but when I saw a code bellow that is value is a string of the same website (“warning”:”This endpoint is deprecated and will soon be disabled.”). it worked flawlessly so im thinking .

.toString()

but i dont know where i am going put the code in

my code is:

} else if (command === "bazaar") {
    let getBazaar = async () => {
        let response = await axios.get(
            'https://api.hypixel.net/skyblock/bazaar/product?key=a8394dae-033b-4ce5-a1a1-fb773cf2386f&productId=PORK'
        );
        let bazaar = response.data;
        return bazaar;
    };
    let bazaarValue = await getBazaar();
    console.log(bazaarValue)
    message.channel.send(`Buy Price: ${bazaarValue.buyPrice}`)

Answer

This doesn’t seem to be an error in your code. Just a legitimate warning from the API host stating that the url you are using (https://api.hypixel.net/skyblock/bazaar/product?key=a8394dae-033b-4ce5-a1a1-fb773cf2386f&productId=PORK) will be disabled.

As you mentioned where you are trying to send (“buyPrice”: 11.0), do read the comment by ippi, you need to see the json that the API is returning and find the value properly.

As for the message send command, (`Buy Price: ${bazaarValue.buyPrice}`) will always be a string, no matter what type bazaarValue.buyPrice is.



Source: stackoverflow