Search code examples
javascriptdiscord.jsroblox

How would I get the full response from this Axios request?


I'm trying to get some data from a HTTP request (via Axios), however my issue is that I'm unsure of how I can get the "imageUrl" from it.

axios request

As you can see in the above image, this is the response I get. Below is the code I'm currently using:

function getAvatarURL(userID) {
    axios.get(`https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${userID}&size=420x420&format=Png&isCircular=false`)
        .then(r => {
            console.log(r.data)
        })
}

r.data.data returns what is in the image.

When I try and do console.log(r.data.data.imageUrl) is simply returns 'Undefined'

How would I go about getting the imageUrl from this?


Solution

  • The API is returning an Array of Objects. You should first select the first element within the array to get the imageURL You should change your console.log line to

    console.log(r.data[0].imageUrl)
    

    This should make it output as you expect it to be.