Lua
Lua
Microsoft Teams - List Team Members
See more Microsoft Teams Examples
Get the members of a team.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Implements the following CURL command:
-- curl -X GET https://graph.microsoft.com/v1.0/teams/{teamsId}/members \
-- -H 'authorization: Bearer ACCESS_TOKEN'
-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code
-- Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.auth_token = "ACCESS_TOKEN"
http:set_url_var("teamsId", "285c8d65-d8b5-447a-91c7-85593d50c826")
local sbResponseBody = chilkat.StringBuilder.new()
local success = http:quick_get_sb("https://graph.microsoft.com/v1.0/teams/{$teamsId}/members", sbResponseBody)
if not success then
print(http.last_error_text)
return
end
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(http.last_header)
print("Failed.")
return
end
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('285c8d65-d8b5-447a-91c7-85593d50c826')/members",
-- "@odata.count": 1,
-- "value": [
-- {
-- "@odata.type": "#microsoft.graph.aadUserConversationMember",
-- "id": "Mjg1YzhkNjUtZDhiNS00NDdhLTkxYzctODU1OTNkNTBjODI2IyM0ZWU3MzJjMz0zMjJlLTRhNmItYjcyOS0yZmQxZWI1YzYwMDQ=",
-- "roles": [
-- "owner"
-- ],
-- "displayName": "Joe Smith",
-- "userId": "4ee732c3-322e-4a6b-b729-2fd1eb5c6004",
-- "email": "admin@chilkat365.com"
-- }
-- ]
-- }
-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
local odata_type = ""
local id = ""
local displayName = ""
local userId = ""
local email = ""
local j = 0
local count_j = 0
local strVal = ""
local odata_context = jResp:string_of("\"@odata.context\"")
local odata_count = jResp:int_of("\"@odata.count\"")
local i = 0
local count_i = jResp:size_of_array("value")
while i < count_i do
jResp.i = i
odata_type = jResp:string_of("value[i].\"@odata.type\"")
id = jResp:string_of("value[i].id")
displayName = jResp:string_of("value[i].displayName")
userId = jResp:string_of("value[i].userId")
email = jResp:string_of("value[i].email")
j = 0
count_j = jResp:size_of_array("value[i].roles")
while j < count_j do
jResp.j = j
strVal = jResp:string_of("value[i].roles[j]")
j = j + 1
end
i = i + 1
end