cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1223
Views
5
Helpful
1
Replies

Import photo from O365 to Webex

dshumake
Level 4
Level 4

Does any know how I update user photos using the picture from o365

1 Reply 1

zackoch
Level 1
Level 1

@dshumake  If you're crafty you can automate this - 

 

Here's the python I wrote for my implementation:

logfile = open('C:\\inetpub\\wwwroot\\logfile.txt', 'a+')

api_endpoint_token = '<insert api token endpoint url here>'
api_endpoint_members = '<insert api members endpoint url here>'
api_client_id = '<insert graph client id here>'
api_client_secret = '<insert graph client secret here>'
api_scope = 'https://graph.microsoft.com/.default'
api_grant_type = 'client_credentials'


def get_token():
    payload = {
        'grant_type': api_grant_type,
        'client_id': api_client_id,
        'client_secret': api_client_secret,
        'scope': api_scope
    }
    r = requests.post(api_endpoint_token, data=payload).json()
    api_access_token = r['access_token']
    return api_access_token


def get_members():
    headers = {
        'Authorization': "Bearer " + get_token()
    }
    return requests.get(api_endpoint_members, headers=headers).json()

def get_photo(upn):
    headers = {
        'Authorization': "Bearer " + get_token(),
        'Content-Type': 'image/jpg'
    }
    return requests.get(f'https://graph.microsoft.com/v1.0/users/{upn}/photo/$value', headers=headers)

for person in get_members()['value']:
    try:
        if get_photo(person['mail']).status_code == 200:
            with open('C:\\inetpub\\wwwroot\\images\\' + person['mail'].lower() + '.jpg', 'wb') as f:
                f.write(get_photo(person['mail']).content)
        elif get_photo(person['mail']).status_code == 404:
            logfile.write(str(datetime.datetime.now()) + ' No photo found for ' + person['mail'].lower() + '\n')
    except Exception as e:
        logfile.write(str(datetime.datetime.now()) + ' ' + str(e) + '\n')
logfile.write(str(datetime.datetime.now()) + ' Script Finished\n')
logfile.close()

runs as a scheduled job every day at 7PM.

 

You need access to the microsoft graph API for your org. 

 

The folder that the pictures are stored in is just an directory that is served using a Webserver but local to the network. If windows you can use IIS, or Linux Apache or Nginx.

 

Then within the Cisco Directory Connector there's a Avatar section under configuration - just point to where it's grabbing the images.
c_connector.png

 

Anyway, that's how I'm doing it, but I'm sure there's other methods!

Getting Started

Welcome to the Webex Community. This is your home to ask questions, share knowledge, and attend live webinars.