Sample code for 30+ languages & platforms
Xbase++

Microsoft Teams - List Team Members

See more Microsoft Teams Examples

Get the members of a team.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cOdata_type
LOCAL cId
LOCAL cDisplayName
LOCAL cUserId
LOCAL cEmail
LOCAL j
LOCAL nCount_j
LOCAL cStrVal
LOCAL cOdata_context
LOCAL nOdata_count
LOCAL i
LOCAL nCount_i

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

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

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

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://graph.microsoft.com/v1.0/teams/{$teamsId}/members", oSbResponseBody)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oSbResponseBody:destroy()
    RETURN
ENDIF

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp:Emit()

nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oHttp:LastHeader
    ? "Failed."
    oHttp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    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

cOdata_context := oJResp:StringOf('"@odata.context"')
nOdata_count := oJResp:IntOf('"@odata.count"')
i := 0
nCount_i := oJResp:SizeOfArray("value")
DO WHILE i < nCount_i
    oJResp:I := i
    cOdata_type := oJResp:StringOf('value[i]."@odata.type"')
    cId := oJResp:StringOf("value[i].id")
    cDisplayName := oJResp:StringOf("value[i].displayName")
    cUserId := oJResp:StringOf("value[i].userId")
    cEmail := oJResp:StringOf("value[i].email")
    j := 0
    nCount_j := oJResp:SizeOfArray("value[i].roles")
    DO WHILE j < nCount_j
        oJResp:J := j
        cStrVal := oJResp:StringOf("value[i].roles[j]")
        j := j + 1
    ENDDO
    i := i + 1
ENDDO

oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()