PureBasic
PureBasic
Microsoft Teams - List Team Members
See more Microsoft Teams Examples
Get the members of a team.Chilkat PureBasic Downloads
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; 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.
CkHttp::setCkAuthToken(http, "ACCESS_TOKEN")
CkHttp::ckSetUrlVar(http,"teamsId","285c8d65-d8b5-447a-91c7-85593d50c826")
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkHttp::ckQuickGetSb(http,"https://graph.microsoft.com/v1.0/teams/{$teamsId}/members",sbResponseBody)
If success = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(jResp,sbResponseBody)
CkJsonObject::setCkEmitCompact(jResp, 0)
Debug "Response Body:"
Debug CkJsonObject::ckEmit(jResp)
respStatusCode.i = CkHttp::ckLastStatus(http)
Debug "Response Status Code = " + Str(respStatusCode)
If respStatusCode >= 400
Debug "Response Header:"
Debug CkHttp::ckLastHeader(http)
Debug "Failed."
CkHttp::ckDispose(http)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
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
odata_type.s
id.s
displayName.s
userId.s
email.s
j.i
count_j.i
strVal.s
odata_context.s = CkJsonObject::ckStringOf(jResp,Chr(34) + "@odata.context" + Chr(34))
odata_count.i = CkJsonObject::ckIntOf(jResp,Chr(34) + "@odata.count" + Chr(34))
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"value")
While i < count_i
CkJsonObject::setCkI(jResp, i)
odata_type = CkJsonObject::ckStringOf(jResp,"value[i]." + Chr(34) + "@odata.type" + Chr(34))
id = CkJsonObject::ckStringOf(jResp,"value[i].id")
displayName = CkJsonObject::ckStringOf(jResp,"value[i].displayName")
userId = CkJsonObject::ckStringOf(jResp,"value[i].userId")
email = CkJsonObject::ckStringOf(jResp,"value[i].email")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"value[i].roles")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
strVal = CkJsonObject::ckStringOf(jResp,"value[i].roles[j]")
j = j + 1
Wend
i = i + 1
Wend
CkHttp::ckDispose(http)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure