Application set icon

Hi,

I’m having trouble with the following code, and I’m not sure why it’s not working as expected. Specifically, I’m trying to upload an image to the IdentityNow API ( set-icon | SailPoint Developer Community). Here’s the relevant part of the code:

headers = {
  'Content-Type': 'multipart/form-data',
  'Accept': 'application/json',
  'Authorization': 'Bearer ' + token
}
payload = {}

files=[
  ('image', ('jupyter.png', open('./jupyter.png','rb'), 'application/octet-stream')),
]

url = "https://<tenant>.api.identitynow.com/beta/icons/application/:appid"

response = session.request("PUT",url=url,headers=headers,data=payload,files=files)

print(response.text)

I always have a

{"messages":[{"localeOrigin":"DEFAULT","text":"An internal fault occurred.","locale":"en-US"},{"localeOrigin":"REQUEST","text":"An internal fault occurred.","locale":"en-US"}],"detailCode":"500.0 Internal fault","trackingId":"2c0444766e79432ba3b33161d69e2d41"}

I suspect the issue might be related to the files parameter or the API endpoint itself. Could you help me identify what might be going wrong ?

PS : It works well with the test request on the doc page, i upload the file and set params and i get a 200 code.

Thanks in advance!

Hey @ethancls

Try this :



headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer ' + token
}

files = [
  ('image', ('jupyter.png', open('./jupyter.png','rb'), 'image/png')),
]

url = "https://sailpoint.api.identitynow.com/beta/icons/application/12345"

response = session.request("PUT", url=url, headers=headers, files=files)

print(response.text)
  • Do not manually set Content-Type to multipart/form-data:
  • The requests library will automatically set the correct Content-Type header with a boundary, which is crucial for proper multipart formatting.
  • You should remove 'Content-Type': 'multipart/form-data' from headers. Otherwise, you’ll likely get a malformed request.
  • In the context of multipart file uploads using files=... in requests, adding data=... is only necessary if you’re also sending additional form fields along with the file (e.g., name, description, etc.).

Since your payload = {} is an empty dictionary, it has no effect whether it’s included or not.

  • File MIME type:
  • You’re using 'application/octet-stream'. It’s okay, but if you know it’s a PNG, it’s better to use 'image/png':
1 Like

Hey,

Thanks a lot for your reponse ! It works, i was not aware of the content-type with form-data. It save me a lot of time :slight_smile:

1 Like