Sample code for 30+ languages & platforms
Lianja

Microsoft Teams - List Team Members

See more Microsoft Teams Examples

Get the members of a team.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loHttp = createobject("CkHttp")

// 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.
loHttp.AuthToken = "ACCESS_TOKEN"

loHttp.SetUrlVar("teamsId","285c8d65-d8b5-447a-91c7-85593d50c826")

loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb("https://graph.microsoft.com/v1.0/teams/{$teamsId}/members",loSbResponseBody)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    release loHttp
    release loSbResponseBody
    return
endif

loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    release loHttp
    release loSbResponseBody
    release loJResp
    return
endif

// 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

lcOdata_context = loJResp.StringOf('"@odata.context"')
lnOdata_count = loJResp.IntOf('"@odata.count"')
i = 0
lnCount_i = loJResp.SizeOfArray("value")
do while i < lnCount_i
    loJResp.I = i
    lcOdata_type = loJResp.StringOf('value[i]."@odata.type"')
    lcId = loJResp.StringOf("value[i].id")
    lcDisplayName = loJResp.StringOf("value[i].displayName")
    lcUserId = loJResp.StringOf("value[i].userId")
    lcEmail = loJResp.StringOf("value[i].email")
    j = 0
    lnCount_j = loJResp.SizeOfArray("value[i].roles")
    do while j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("value[i].roles[j]")
        j = j + 1
    enddo
    i = i + 1
enddo


release loHttp
release loSbResponseBody
release loJResp