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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Building a Flow that a...
Power Automate
Suggested Answer

Building a Flow that also updates Teams Work Location

(1) ShareShare
ReportReport
Posted on by 4
We have been using for some time a flows that does the following:
Flow 1 -
1. Recurrence - runs every day at 6am
2. Condition - checks that it is Monday to Friday (if weekend it terminates)
3. List rows present in a table - looks at the Response spreadsheet which has the following rows - Date, Name, Team, Location, Response, Comment, Email Address.
4. Apply to each 
 i. Sends a Teams Message (Post a choice of options as the Flow bot to a user) to a Teams Chat (all members needs to be in it) every business day that asks them where they are working today (at home, at office, unplanned leave, work - other, planned leave). 
ii. Their response is the captured in a Response spreadsheet of "today's" responses replacing yesterday's response (Update a Row)
iii. It also appends their response (Add Row to) to the another Long Term Record spreadsheet for a long term record (useful for tax claims).

iv. It posts to the Teams Channel (Post a message as the Flow bot to a channel) their response when they make it.
 
Based on the above some of the options indicate that they are "in the office" and other are "remote.  How can we within teams, also set each persons Work Location within team?

But it looks to come from outside and all of these users are authenticated etc.
Categories:
I have the same question (0)
  • WillPage Profile Picture
    2,307 Super User 2025 Season 2 on at
    Firstly there's no need to check the weekday. Simply set your trigger to weekly and select only Monday to Friday as the trigger days.
     
    As for setting the work location. It doesn't look like you can do this with Application permissions (although you could try), but you can do it for "yourself" and by "yourself" I mean the user whom the flow is running under. You can use the Send an HTTP request to SharePoint (of all things) to send a POST request to https://presence.teams.microsoft.com/v1/me/workLocation with a JSON body like 
    {
            "location": "1",
            "expiration": "2025-06-10T00:00:00.0Z"
    }
    ..where 1 is work and 2 is home and the timestamp is the UTC where you want it to reset to the previous location

    So if you can build something with a button trigger that runs in the user context, and send a link to run the flow via your adaptive card, maybe you can make it go.
  • Suggested answer
    Riyaz_riz11 Profile Picture
    3,893 Super User 2025 Season 2 on at
    Hi,
     
    Step 1: Register an App in Azure AD
    Go to https://portal.azure.com
    Navigate to Azure Active Directory → App registrations
    Click New registration
    Name: TeamsWorkLocationUpdater
    Supported account types: Select your org only (Single tenant)
    Redirect URI: Leave blank (for now)
    Click Register
    Step 2: Add API Permissions
    After registration, go to API Permissions
    Click + Add a permission → Microsoft Graph
    Choose Delegated permissions
    User.ReadWrite
    Presence.ReadWrite.All (if setting presence too)
    User.ReadWrite.All
    (Optional if setting working hours/locations via beta: UserSettings.ReadWrite)
    Click Grant admin consent for your tenant.
    Step 3: Create a Secret
    Go to Certificates & secrets → New client secret
    Description: PowerAutomateSecret
    Expiry: 6-12 months recommended
    Copy the secret value immediately. You’ll use it in Power Automate.
    Step 4: Save App Details
    Copy these and store them:
    Tenant ID
    Client ID
    Client Secret (just generated)
    PART 2: Build Power Automate Flow
    Step 1: Your Existing Flow (as described)
    You already have:
    Recurrence trigger → Weekday check → List rows in Excel
    Apply to each: For each user, send Teams Adaptive Card
    Capture their response
    Update row and append to master log
    Step 2: Add Work Location Logic
    ➤ After capturing user’s response, insert a Switch or Condition
    Condition:
    If Response = "At Office" OR "Work - Other"
    → Set location variable = "Office"
    Else
    → Set location variable = "Remote"
    Step 3: Add HTTP Action to Call Graph API
    ➤ Add an HTTP step (Standard or Premium license required)
    Use the values from Azure registration earlier.
    Action: HTTP
    Property    Value
    Method    PATCH
    URI    https://graph.microsoft.com/beta/users/<UserEmail>/settings/workingLocation
    Headers    
    {
      "Authorization": "Bearer <access_token>",
      "Content-Type": "application/json"
    }
    | Body (example): |

    {
      "location": {
        "displayName": "@{variables('WorkLocation')}",
        "building": "HQ",
        "floor": "2",
        "desk": "Unassigned"
      },
      "recurrence": {
        "pattern": {
          "type": "daily",
          "interval": 1
        },
        "range": {
          "type": "endDate",
          "startDate": "@{utcNow('yyyy-MM-dd')}",
          "endDate": "@{utcNow('yyyy-MM-dd')}"
        }
      }
    }
    Replace <UserEmail> with dynamic user email from your Excel sheet.
    Step 4: Get Access Token via HTTP (Token Step)
    Before the HTTP PATCH request above, insert a "Get Token" step.
    ➤ Add another HTTP action: Get Token
    Property    Value
    Method    POST
    URI    https://login.microsoftonline.com/<TenantID>/oauth2/v2.0/token
    Headers    

    {
      "Content-Type": "application/x-www-form-urlencoded"
    }
    | Body |
    client_id=<YourClientID>
    &scope=https://graph.microsoft.com/.default
    &client_secret=<YourClientSecret>
    &grant_type=client_credentials
    ➤ Parse Token:
    Use a Parse JSON step to extract the access_token
    Schema example:
    {
      "type": "object",
      "properties": {
        "access_token": {
          "type": "string"
        }
      }
    }
    Use @body('Parse_Token')?['access_token'] in the Authorization header of your main HTTP request.

     
    If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
    Regards,
    Riyaz

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard