web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Change User image with...
Power Automate
Answered

Change User image with Graph API

(0) ShareShare
ReportReport
Posted on by 59

Howdy,
I'm currently building a Power Automate flow which could be used to change a user's Microsoft profile picture.
The following flow consists of a Power Apps trigger which supplies user's e-mail and image through an attachments control.

ValiantKillmore_1-1689668554491.png
Image itself is grabbed from an image object in powerapps using the following formula:

ValiantKillmore_3-1689668894166.png

For the graph API I'm using the https://graph.microsoft.com/v1.0/users/{userID}/photo/ command, where userID is the e-mail.
Though, when running the flow, I get the following error:

ValiantKillmore_0-1689669550768.png

Maybe someone can point to very obvious mistakes that I'm committing right now or some other approach I should be using to changing a user's image, because it feels like I haven't gotten anywhere in the last two hours of tinkering I've done.

Thanks : - )

Categories:
I have the same question (0)
  • Verified answer
    ValiantKillmore Profile Picture
    59 on at

    Turns out I had to have "$value" at the end of the URI.
    Afterwards it worked

  • mgisbert Profile Picture
    71 on at

    I'm doing it like that and it's throwing "Unknown error". Anybody knows why? 

     

    mgisbert_0-1703238748840.png

     

    mgisbert_1-1703238786232.png  mgisbert_2-1703238840137.png

     

  • ValiantKillmore Profile Picture
    59 on at

    Hey,
    I checked on my solution and I perform an extra step in manipulating the base64 image in powerapps before sending it off to power automate.
    Try plugging this in your code and sending the "base64image" value to the power automate instead:
    Set(base64image, Mid(var_ImageToBase64, Find(",", var_ImageToBase64) + 1, Len(var_ImageToBase64) - Find(",", var_ImageToBase64) - 1 ) );

  • mgisbert Profile Picture
    71 on at

    I managed to do it with two Compose steps. The first one with 

    substring(replace(triggerBody()['text_1'], 'data:image/jpeg;base64,', ''), 1, sub(length(replace(triggerBody()['text_1'], 'data:image/jpeg;base64,', '')), 2))

    and the second one with: 

    base64ToBinary(outputs('Compose_2'))

     

    and all this at the Save button (I have a collection named 'users' which has all the users info and they're showed on a Gallery): 

    Set(var_ImageToBase64, JSON(UploadedImage1.Image, JSONFormat.IncludeBinaryData));
    If(
     AddMediaButton1.Media <> Blank(),
     Set(var_ImageToBase64, JSON(UploadedImage1.Image, JSONFormat.IncludeBinaryData));
     Set(result1, 'UPM|ChangeUserPicture'.Run(Gallery1.Selected.id, var_ImageToBase64));
     Reset(AddMediaButton1);
    );
    
    Set(
     result2,
     'UPM|ModifyUser'.Run(
     Gallery1.Selected.id, 
     If(IsBlank(CompanyNameInput.Text), "-", CompanyNameInput.Text), 
     If(IsBlank(DepartmentInput.Text), "-", DepartmentInput.Text), 
     If(IsBlank(JobTitleInput.Text), "-", JobTitleInput.Text), 
     If(IsBlank(CityInput.Text), "-", CityInput.Text), 
     If(IsBlank(PostalCodeInput.Text), "-", PostalCodeInput.Text), 
     If(IsBlank(CountryInput.Text), "-", CountryInput.Text), 
     If(IsBlank(OfficeLocationInput.Text), "-", OfficeLocationInput.Text), 
     If(IsBlank(MobilePhoneInput.Text), "-", MobilePhoneInput.Text)
     )
    );
    
    If(
     (UploadedImage1.Image <> Blank() || result1.response = "204") && result2.response = "204", 
     Notify("User modified.", NotificationType.Success);
     Patch(users, LookUp(users, id = Gallery1.Selected.id), 
     {
     companyName: CompanyNameInput.Text, 
     department: DepartmentInput.Text, 
     jobTitle: JobTitleInput.Text, 
     city: CityInput.Text, 
     postalCode: PostalCodeInput.Text, 
     country: CountryInput.Text, 
     officeLocation: OfficeLocationInput.Text, 
     mobilePhone: MobilePhoneInput.Text,
     UserPhoto: If(UploadedImage1.Image <> Blank(), UploadedImage1.Image, LookUp(users, id = Gallery1.Selected.id).UserPhoto)
     }
     );
     ClearCollect(
     users, 
     AddColumns(
     'UPM|LoadUsers'.Run(), 
     "UserPhoto", 
     Office365Users.UserPhotoV2(id)
     )
     );
    );
    If(result2.response <> "204", 
     Notify("Error occurred while trying to modify user.", NotificationType.Error)
    );



    The only thing here is that just jpeg is working to change the user picture. I tried to modify the first Compose to allow png as well but it didn't work. Any way to do it for several images types? 

    Thanks, 
    Miguel 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 304

#2
David_MA Profile Picture

David_MA 245 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 243 Most Valuable Professional

Last 30 days Overall leaderboard