Forum Discussion

Theangrydog's avatar
Theangrydog
Copper Contributor
Feb 16, 2023

Bulk add contacts to Teams

Hi all,

 

Is there any way to bulk add contacts to Teams?  This is under the Chat > Contacts section that I am referring to?

 

Whenever we have a new user join the company, they have to manually add contacts to Teams.  There must be an easier way than this?

 

Thanks.

  • Theangrydog 

     

    Hello, are you proficient with scripting?
    With some tweaking you could use this script I made, I plan to improve it and publish it

     

    Import-Module AADInternals
    
    #This will prompt for credentials so it supports MFA login
    $token = Get-AADIntAccessTokenForTeams
    
    $skypeToken = Get-AADIntSkypeToken -AccessToken $token
    
    Invoke-WebRequest -UseBasicParsing -Uri "https://teams.microsoft.com/api/mt/part/amer-03/beta/contacts/buddylist/RgAAAAClggzHMV84T7CuooP5TJakBwCn8NvzZtw-Rb1w2SeP68PUAAALK2GmAACn8NvzZtw-Rb1w2SeP68PUAAALLAIqAAAA0/managebuddies?migrationRequested=true&federatedContactsSupported=true" `
    -Method "POST" `
    -Headers @{
    "authority"="teams.microsoft.com"
      "method"="POST"
      "path"="/api/mt/part/amer-03/beta/contacts/buddylist/RgAAAAClggzHMV84T7CuooP5TJakBwCn8NvzZtw-Rb1w2SeP68PUAAALK2GmAACn8NvzZtw-Rb1w2SeP68PUAAALLAIqAAAA0/managebuddies?migrationRequested=true&federatedContactsSupported=true"
      "scheme"="https"
      "accept"="application/json, text/plain, */*"
      "accept-encoding"="gzip, deflate, br"
      "accept-language"="en-US,en;q=0.9,es;q=0.8,es-ES;q=0.7,en-GB;q=0.6"
      "authorization"="Bearer $token"
      "origin"="https://teams.microsoft.com"
      "referer"="https://teams.microsoft.com/_"
      "sec-ch-ua"="`"Chromium`";v=`"110`", `"Not A(Brand`";v=`"24`", `"Microsoft Edge`";v=`"110`""
      "sec-ch-ua-mobile"="?0"
      "sec-ch-ua-platform"="`"Windows`""
      "sec-fetch-dest"="empty"
      "sec-fetch-mode"="cors"
      "sec-fetch-site"="same-origin"
      "x-anchormailbox"="email address removed for privacy reasons"
      "x-ms-client-env"="pds-prod-azsc-usea-01"
      "x-ms-client-type"="web"
      "x-ms-client-version"="1415/1.0.0.2023020626"
      "x-ms-scenario-id"="468"
      "x-ms-session-id"="cef7e701-18bc-4767-60f8-3ec240794968"
      "x-ms-user-type"="null"
      "x-ringoverride"="general"
      "x-skypetoken"=$skypeToken
    } `
    -ContentType "application/json;charset=UTF-8" `
    -Body "{`"add`":[{`"mri`":`"8:orgid:7c4cb78f-aa4f-4cc6-953f-d0b55c1ca6d9`",`"displayName`":`"Isaiah Langer`",`"isFederated`":false,`"email`":`"email address removed for privacy reasons`"}]}"

    the last line is the one you need to tweak with the desired contact to add to favorites.

     

    I'll get back when I improve and publish this on my blog...

  • Theangrydog 

     

    Hello, are you proficient with scripting?
    With some tweaking you could use this script I made, I plan to improve it and publish it

     

    Import-Module AADInternals
    
    #This will prompt for credentials so it supports MFA login
    $token = Get-AADIntAccessTokenForTeams
    
    $skypeToken = Get-AADIntSkypeToken -AccessToken $token
    
    Invoke-WebRequest -UseBasicParsing -Uri "https://teams.microsoft.com/api/mt/part/amer-03/beta/contacts/buddylist/RgAAAAClggzHMV84T7CuooP5TJakBwCn8NvzZtw-Rb1w2SeP68PUAAALK2GmAACn8NvzZtw-Rb1w2SeP68PUAAALLAIqAAAA0/managebuddies?migrationRequested=true&federatedContactsSupported=true" `
    -Method "POST" `
    -Headers @{
    "authority"="teams.microsoft.com"
      "method"="POST"
      "path"="/api/mt/part/amer-03/beta/contacts/buddylist/RgAAAAClggzHMV84T7CuooP5TJakBwCn8NvzZtw-Rb1w2SeP68PUAAALK2GmAACn8NvzZtw-Rb1w2SeP68PUAAALLAIqAAAA0/managebuddies?migrationRequested=true&federatedContactsSupported=true"
      "scheme"="https"
      "accept"="application/json, text/plain, */*"
      "accept-encoding"="gzip, deflate, br"
      "accept-language"="en-US,en;q=0.9,es;q=0.8,es-ES;q=0.7,en-GB;q=0.6"
      "authorization"="Bearer $token"
      "origin"="https://teams.microsoft.com"
      "referer"="https://teams.microsoft.com/_"
      "sec-ch-ua"="`"Chromium`";v=`"110`", `"Not A(Brand`";v=`"24`", `"Microsoft Edge`";v=`"110`""
      "sec-ch-ua-mobile"="?0"
      "sec-ch-ua-platform"="`"Windows`""
      "sec-fetch-dest"="empty"
      "sec-fetch-mode"="cors"
      "sec-fetch-site"="same-origin"
      "x-anchormailbox"="email address removed for privacy reasons"
      "x-ms-client-env"="pds-prod-azsc-usea-01"
      "x-ms-client-type"="web"
      "x-ms-client-version"="1415/1.0.0.2023020626"
      "x-ms-scenario-id"="468"
      "x-ms-session-id"="cef7e701-18bc-4767-60f8-3ec240794968"
      "x-ms-user-type"="null"
      "x-ringoverride"="general"
      "x-skypetoken"=$skypeToken
    } `
    -ContentType "application/json;charset=UTF-8" `
    -Body "{`"add`":[{`"mri`":`"8:orgid:7c4cb78f-aa4f-4cc6-953f-d0b55c1ca6d9`",`"displayName`":`"Isaiah Langer`",`"isFederated`":false,`"email`":`"email address removed for privacy reasons`"}]}"

    the last line is the one you need to tweak with the desired contact to add to favorites.

     

    I'll get back when I improve and publish this on my blog...

    • Theangrydog's avatar
      Theangrydog
      Copper Contributor
      Hi Andres,

      Thanks for your reply - I'm not brilliant with scripting, but I am working on it.
      Not sure how I managed to mark your reply as the best answer lol.

Resources