Sample code for 30+ languages & platforms
B4X

Outlook List Contacts

See more Outlook Contact Examples

List Outlook Contacts

Chilkat B4X Downloads

B4X
Dim success As Boolean = False

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

Dim http As ChilkatHttp
http.Initialize("http")

'  Use your previously obtained access token here: Get Outlook Contacts OAuth2 Access Token (Azure AD v2.0 Endpoint).

Dim jsonToken As ChilkatJsonObject
jsonToken.Initialize
success = jsonToken.LoadFile("qa_data/tokens/outlookContacts.json")
If success = False Then
    Log(jsonToken.LastErrorText)
    Return
End If

http.AuthToken = jsonToken.StringOf("access_token")

'  Send the following GET:

'  GET https://graph.microsoft.com/v1.0/me/contacts
Dim sbJson As ChilkatStringBuilder
sbJson.Initialize
success = http.QuickGetSb("https://graph.microsoft.com/v1.0/me/contacts", sbJson)
If success = False Then
    Log(http.LastErrorText)
    Return
End If


Dim statusCode As Int = http.LastStatus
Log("Response status code = " & statusCode)

If statusCode <> 200 Then
    Log(sbJson.GetAsString)
    Log("Failed.")
    Return
End If


Dim jResp As ChilkatJsonObject
jResp.Initialize
jResp.LoadSb(sbJson)
jResp.EmitCompact = False
Log(jResp.Emit)

'  Sample output:

'  Use this online tool to generate parsing code from sample JSON: 
'  Generate Parsing Code from JSON

'  {
'    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4ee732c3-322e-4a6b-b729-2fd1eb5c6004')/contacts",
'    "value": [
'      {
'        "@odata.etag": "W/\"EQAAABYAAABUcG0qWqkmQYqWLHQataQxAAD0iYfT\"",
'        "id": "AAMkADYzZWE3YmZmLWU0YzgtNGNkZC04MGE1LWFiYTFlNTRlY2QwYQBGAAAAAAAu7cUXL5YOTrdsUIw7-v8FBwBUcG0qWqkmQYqWLHQataQxAAAAAAEOAABUcG0qWqkmQYqWLHQataQxAAD0sxexAAA=",
'        "createdDateTime": "2021-06-29T16:32:05Z",
'        "lastModifiedDateTime": "2021-06-29T16:32:06Z",
'        "changeKey": "EQAAABYAAABUcG0qWqkmQYqWLHQataQxAAD0iYfT",
'        "categories": [
'        ],
'        "parentFolderId": "AAMkADYzZWE3YmZmLWU0YzgtNGNkZC04MGE1LWFiYTFlNTRlY2QwYQAuAAAAAAAu7cUXL5YOTrdsUIw7-v8FAQBUcG0qWqkmQYqWLHQataQxAAAAAAEOAAA=",
'        "birthday": null,
'        "fileAs": "",
'        "displayName": "Pavel Bansky",
'        "givenName": "Pavel",
'        "initials": null,
'        "middleName": null,
'        "nickName": null,
'        "surname": "Bansky",
'        "title": null,
'        "yomiGivenName": null,
'        "yomiSurname": null,
'        "yomiCompanyName": null,
'        "generation": null,
'        "imAddresses": [
'        ],
'        "jobTitle": null,
'        "companyName": null,
'        "department": null,
'        "officeLocation": null,
'        "profession": null,
'        "businessHomePage": null,
'        "assistantName": null,
'        "manager": null,
'        "homePhones": [
'        ],
'        "mobilePhone": null,
'        "businessPhones": [
'          "+1 732 555 0102"
'        ],
'        "spouseName": null,
'        "personalNotes": "",
'        "children": [
'        ],
'        "emailAddresses": [
'          {
'            "name": "Pavel Bansky",
'            "address": "pavelb@fabrikam.onmicrosoft.com"
'          }
'        ],
'        "homeAddress": {},
'        "businessAddress": {},
'        "otherAddress": {}
'      },
'  ...
'    ]
'  }



Dim odata_etag As String
Dim id As String
Dim createdDateTime As String
Dim lastModifiedDateTime As String
Dim changeKey As String
Dim parentFolderId As String
Dim birthday As String
Dim fileAs As String
Dim displayName As String
Dim givenName As String
Dim initials As String
Dim middleName As String
Dim nickName As String
Dim surname As String
Dim title As String
Dim yomiGivenName As String
Dim yomiSurname As String
Dim yomiCompanyName As String
Dim generation As String
Dim jobTitle As String
Dim companyName As String
Dim department As String
Dim officeLocation As String
Dim profession As String
Dim businessHomePage As String
Dim assistantName As String
Dim manager As String
Dim mobilePhone As String
Dim spouseName As String
Dim personalNotes As String
Dim j As Int
Dim count_j As Int
Dim strVal As String
Dim name As String
Dim address As String

Dim odata_context As String = jResp.StringOf(Chr(34) & "@odata.context" & Chr(34))
Dim i As Int = 0
Dim count_i As Int = jResp.SizeOfArray("value")
Do While i < count_i
    jResp.I = i
    odata_etag = jResp.StringOf("value[i]." & Chr(34) & "@odata.etag" & Chr(34))
    id = jResp.StringOf("value[i].id")
    createdDateTime = jResp.StringOf("value[i].createdDateTime")
    lastModifiedDateTime = jResp.StringOf("value[i].lastModifiedDateTime")
    changeKey = jResp.StringOf("value[i].changeKey")
    parentFolderId = jResp.StringOf("value[i].parentFolderId")
    birthday = jResp.StringOf("value[i].birthday")
    fileAs = jResp.StringOf("value[i].fileAs")
    displayName = jResp.StringOf("value[i].displayName")
    givenName = jResp.StringOf("value[i].givenName")
    initials = jResp.StringOf("value[i].initials")
    middleName = jResp.StringOf("value[i].middleName")
    nickName = jResp.StringOf("value[i].nickName")
    surname = jResp.StringOf("value[i].surname")
    title = jResp.StringOf("value[i].title")
    yomiGivenName = jResp.StringOf("value[i].yomiGivenName")
    yomiSurname = jResp.StringOf("value[i].yomiSurname")
    yomiCompanyName = jResp.StringOf("value[i].yomiCompanyName")
    generation = jResp.StringOf("value[i].generation")
    jobTitle = jResp.StringOf("value[i].jobTitle")
    companyName = jResp.StringOf("value[i].companyName")
    department = jResp.StringOf("value[i].department")
    officeLocation = jResp.StringOf("value[i].officeLocation")
    profession = jResp.StringOf("value[i].profession")
    businessHomePage = jResp.StringOf("value[i].businessHomePage")
    assistantName = jResp.StringOf("value[i].assistantName")
    manager = jResp.StringOf("value[i].manager")
    mobilePhone = jResp.StringOf("value[i].mobilePhone")
    spouseName = jResp.StringOf("value[i].spouseName")
    personalNotes = jResp.StringOf("value[i].personalNotes")
    j = 0
    count_j = jResp.SizeOfArray("value[i].categories")
    Do While j < count_j
        jResp.J = j
        j = j + 1
    Loop
    j = 0
    count_j = jResp.SizeOfArray("value[i].imAddresses")
    Do While j < count_j
        jResp.J = j
        j = j + 1
    Loop
    j = 0
    count_j = jResp.SizeOfArray("value[i].homePhones")
    Do While j < count_j
        jResp.J = j
        j = j + 1
    Loop
    j = 0
    count_j = jResp.SizeOfArray("value[i].businessPhones")
    Do While j < count_j
        jResp.J = j
        strVal = jResp.StringOf("value[i].businessPhones[j]")
        j = j + 1
    Loop
    j = 0
    count_j = jResp.SizeOfArray("value[i].children")
    Do While j < count_j
        jResp.J = j
        j = j + 1
    Loop
    j = 0
    count_j = jResp.SizeOfArray("value[i].emailAddresses")
    Do While j < count_j
        jResp.J = j
        name = jResp.StringOf("value[i].emailAddresses[j].name")
        address = jResp.StringOf("value[i].emailAddresses[j].address")
        j = j + 1
    Loop
    i = i + 1
Loop