Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use the Slack API to set the profile picture?

I am running a Slack team for a gaming community. My users all have avatars in the game and I am already using the Slack API to automatically set their Slack user name to their in-game name, so its easier for people to be recognized.

In addition I would also like to automatically set their profile picture in Slack with their avatar picture from the game. However I could not figure out a way to do it, so my question is can it be done and if yes, how?

My current starting point is the undocumented API method users.profile.set which allows me to set the profile of a user (see below for an example of a user profile). So far I've been able to modify:

  • first_name
  • last_name
  • title
  • phone
  • skype

The user profile also contains the URL to the profile picture, but I was so far not able to change it. I tried external URLs, and URLs of images already uploaded on Slack.

Here is a link to my documentation of the "undocumented" Slack API method users.profile.set with all options that I could figure out so far.

Any help would be hugely appreciated.


Update November 2017

In the meantime Slack has added a new API method called users.setPhoto for setting profile photos. However, this new method does not solve this question, because it only works for your own user (or more precisely the user you have an access token for, e.g. you not specify another user ID).

I am looking for a way to change the profile pictures of all users on my Slack team by a Slack app / bot.


Example of a user profile:

{
id: "U12345678",
team_id: "T12345678",
name: "erik.kalkoken",
deleted: false,
status: null,
color: "9f69e7",
real_name: "Erik Kalkoken",
tz: "America/Chicago",
tz_label: "Central Daylight Time",
tz_offset: 3600,
profile: {
avatar_hash: "XXX",
first_name: "Erik",
last_name: "Kalkoken",
title: "",
phone: "",
skype: "",
image_24: "https://avatars.slack-edge.com/2016-03-19/XXX_24.jpg",
image_32: "https://avatars.slack-edge.com/2016-03-19/XXX_32.jpg",
image_48: "https://avatars.slack-edge.com/2016-03-19/XXX_48.jpg",
image_72: "https://avatars.slack-edge.com/2016-03-19/XXX_72.jpg",
image_192: "https://avatars.slack-edge.com/2016-03-19/XXX_192.jpg",
image_512: "https://avatars.slack-edge.com/2016-03-19/XXX_512.jpg",
image_1024: "https://avatars.slack-edge.com/2016-03-19/XXX_512.jpg",
image_original: "https://avatars.slack-edge.com/2016-03-19/XXX_original.jpg",
real_name: "Erik Kalkoken",
real_name_normalized: "Erik Kalkoken",
email: "[email protected]"
},
is_admin: false,
is_owner: false,
is_primary_owner: false,
is_restricted: false,
is_ultra_restricted: false,
is_bot: false,
has_2fa: false
}
like image 206
Erik Kalkoken Avatar asked Apr 06 '16 11:04

Erik Kalkoken


3 Answers

After messing around with it for a little, it's possible to use the undocumented users.setPhoto endpoint:

curl https://slack.com/api/users.setPhoto \
    -F "token=<removed>" \
    -F "image=@/path/to/image.jpg"

Unfortunately it will resize your avatar which removes the ability to upload animated gifs.

like image 130
Jay Avatar answered Oct 21 '22 15:10

Jay


I don't think the profile picture API is available yet. I read a while back that it was on their TODO list.

like image 24
John Difool Avatar answered Oct 21 '22 15:10

John Difool


I was able to get it to work using Jay Querie's method. The two difference was I gave the full path and I put the image first. So in my case:

curl https://slack.com/api/users.setPhoto -F "image=@C:\Users\name\Pictures\dojocat.jpg" -F "token=xxxx-123-123-123-123"

Originally when I was using gitbash to run the curl and it was searching for the image in the directory where my gitbash was installed / being executed. So if I put the dojocat.jpg next to my gitbash executable it would would have found it.

like image 22
Nikolay Arabadzhi Avatar answered Oct 21 '22 17:10

Nikolay Arabadzhi