Fetch my headshot skin from ROBLOX APIs using JavaScript

Hello dear developers,

First off, network, JavaScript, API use, … is clearly something I am a noob at. So please be kind :pray:

My website isn’t an extraordinary built website, it is a GOOGLE SITES website, meaning I don’t have free hand on it.

I am in charge of a simple website for my game. Since I upload my developer notes (like bulletin boards for game updates) on it, I wanted to add a little “sticker” specifying who wrote it:

image


Description of the problem

The obvious problem that I will encounter is if I change my skin. Yet, the image is fetched with a static link, but I would prefer to have it updated automatically using the https://thumbnails.roblox.com/v1/users/avatar-headshot API from ROBLOX.

Here is what I have yet:

<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.4.0/axios.min.js"></script>

<--!Some other stuff...-->

<script>   
    const myUrl = "https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=955444514&size=352x352&format=Png&isCircular=false";
    let image = document.getElementById("Image");

    axios.get(myUrl)
    .then(response => {
      console.log(response);
    })
</script>

<img src="" alt= "UserImage" id="Image"/>

I also tried with the fetch method, and it did not work either.

The problem is that, there is something called “CORS policies” that prevent shady resources to be sent to the client. That being said, the method I tried to use are not working at all.

When taking a look at the request itself,
image

It fetched successfully ! The problem is technically not on ROBLOX’s side since the request is achieved. BUT they did not implement any CORS policies on their end, making it impossible for my client to retrieve this image…


What I would love to know

Do you have any other methods to get this image modified directly? Why are proxies able to fetch APIs and not this simple JS script? I am quite confused about that.

I would love to not use any proxies, just a simple script.

I have a third solution in mind, which would be update an image on the google drive directly, but it would add a human-intervention step, making it not fully autonomous. I tested it, and it does not work. I would need to go on all the previous pages to change the image and keep it updated, unless I host a URL pointing to the image, and change the image whenever I need it…

Thank you for your help :pray:
@Varonex_0

2 Likes

Kinda graced over this post, I’m not an expert in JavaScript, but you should really look into “HttpService”. I’ve never used it, but I’ve seen it used in the context that you’re using real JS in.

Another thing I’m thinking of is just URL magic, I’m pretty sure there’s some URL combination you can use to just automatically fetch the image of any persons avatar. There’s a URL combination to take you to the profile of any username, there should probably be this.

1 Like

The URL that permitted us to fetch the headshot image from a UserId directly was deprecated and the endpoint was removed, sadly.

How could I use HTTPService since it’s within Roblox? I can’t really setup a communication between my website and roblox (website TO roblox*) for multiple reasons…

2 Likes