Help with using thumbnail api

So I have been trying to use the thumbnail uploader api (Publish Api), however I haven’t had success in either the api page itself or in my own code.

my current code is :


gameid = "my game id is here :/"
url = ''.join(['https://publish.roblox.com/v1/games/',gameid,'/thumbnail/image'])

session.post(url, files = {
        'icon': ('thumbnail.png', open('thumbnail.png', 'rb'), 'image/png')
        }
    )

This code returns me the following error:

{
  "errors": [
    {
      "code": 4,
      "message": "Target item is invalid or does not exist.",
      "userFacingMessage": "Something went wrong"
    }
  ]
}

I have both my robloxscurity and xcsrf token in my headers so this isn’t a verification error.
The api gives an additional parameter for use as well, however I couldn’t figure what it was supposed to be based on the documentation.

{
  "targetId": 0
}

Any help solving this problem would be appreciated :smiley:

Hi there. I think I might see the issue.

In your POST request, you are setting the argument files to an array ({}), but the API expects a file.

Try this:

gameid = "123"
url = ''.join(['https://publish.roblox.com/v1/games/',gameid,'/thumbnail/image'])

session.post(url, files = ('thumbnail.png', open('thumbnail.png', 'rb'), 'image/png'))

I am not sure if you are trying to post a THUMBNAIL or the ICON (two different things), but I don’t know if this API supports icons or not. The icon is the picture on the front page of the game (only one can be applied) and the thumbnail(s) are the rectangle ones on the game’s page.

1 Like

Also apologies if I made any syntax errors, I never used python.

This might make it easier… This is what Roblox is expecting in your request:

request = {
    "files": -- A FILE HERE
}

in python {} refers to a dictionary, and as far as my knowledge goes that’s how files should be given using the requests library in python (im basing this off Content-Type in for individual files in python requests - Stack Overflow btw). About the icon thing, i don’t think the name matters (it might) but you are correct in assuming the endpoint for uploading an icon is different (https://www.roblox.com/places/icons/add-icon)

btw I tried using your code, it gave an error in the library itself, not the endpoint, meaning it is not the correct syntax for posting files in requests

session.post(url, files = ('thumbnail.png', open('thumbnail.png', 'rb'), 'image/png'))
gameid = "123"
url = ''.join(['https://publish.roblox.com/v1/games/',gameid,'/thumbnail/image'])
files = {
    'thumbnail': ('thumbnail.png', open('thumbnail.png', 'rb'), 'image/png')
}

session.post(url, files=files.thumbnail) -- i dont know if thats the correct way to index

Otherwise, your original code is right and something must be wrong with the file you are referencing to.

Hi there. I actually figured out it has nothing to do with the file… so let’s revert to the ORIGINAL code.

The actual issue is the ID you are using. It is NOT the one that shows up in the URL. It is the UNIVERSE ID, which can be found when configuring the experience (not the place).

image

image

Apologies for my original confusion, I have no experience with Python. Let me know if this helps with anything!

1 Like

Ah, I see, thank you a lot for the help :smiley:

1 Like

Happy to help! Good luck with your project :heart:

1 Like