Sample code for 30+ languages & platforms
PowerBuilder

Outlook List Contacts

See more Outlook Contact Examples

List Outlook Contacts

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_JsonToken
oleobject loo_SbJson
integer li_StatusCode
oleobject loo_JResp
string ls_Odata_etag
string ls_Id
string ls_CreatedDateTime
string ls_LastModifiedDateTime
string ls_ChangeKey
string ls_ParentFolderId
string ls_Birthday
string ls_FileAs
string ls_DisplayName
string ls_GivenName
string ls_Initials
string ls_MiddleName
string ls_NickName
string ls_Surname
string ls_Title
string ls_YomiGivenName
string ls_YomiSurname
string ls_YomiCompanyName
string ls_Generation
string ls_JobTitle
string ls_CompanyName
string ls_Department
string ls_OfficeLocation
string ls_Profession
string ls_BusinessHomePage
string ls_AssistantName
string ls_Manager
string ls_MobilePhone
string ls_SpouseName
string ls_PersonalNotes
integer j
integer li_Count_j
string ls_StrVal
string ls_Name
string ls_Address
string ls_Odata_context
integer i
integer li_Count_i

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_JsonToken.LoadFile("qa_data/tokens/outlookContacts.json")
if li_Success = 0 then
    Write-Debug loo_JsonToken.LastErrorText
    destroy loo_Http
    destroy loo_JsonToken
    return
end if

loo_Http.AuthToken = loo_JsonToken.StringOf("access_token")

// Send the following GET:

// GET https://graph.microsoft.com/v1.0/me/contacts
loo_SbJson = create oleobject
li_rc = loo_SbJson.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/contacts",loo_SbJson)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_JsonToken
    destroy loo_SbJson
    return
end if

li_StatusCode = loo_Http.LastStatus
Write-Debug "Response status code = " + string(li_StatusCode)

if li_StatusCode <> 200 then
    Write-Debug loo_SbJson.GetAsString()
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_JsonToken
    destroy loo_SbJson
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbJson)
loo_JResp.EmitCompact = 0
Write-Debug loo_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": {}
//     },
// ...
//   ]
// }

ls_Odata_context = loo_JResp.StringOf("~"@odata.context~"")
i = 0
li_Count_i = loo_JResp.SizeOfArray("value")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Odata_etag = loo_JResp.StringOf("value[i].~"@odata.etag~"")
    ls_Id = loo_JResp.StringOf("value[i].id")
    ls_CreatedDateTime = loo_JResp.StringOf("value[i].createdDateTime")
    ls_LastModifiedDateTime = loo_JResp.StringOf("value[i].lastModifiedDateTime")
    ls_ChangeKey = loo_JResp.StringOf("value[i].changeKey")
    ls_ParentFolderId = loo_JResp.StringOf("value[i].parentFolderId")
    ls_Birthday = loo_JResp.StringOf("value[i].birthday")
    ls_FileAs = loo_JResp.StringOf("value[i].fileAs")
    ls_DisplayName = loo_JResp.StringOf("value[i].displayName")
    ls_GivenName = loo_JResp.StringOf("value[i].givenName")
    ls_Initials = loo_JResp.StringOf("value[i].initials")
    ls_MiddleName = loo_JResp.StringOf("value[i].middleName")
    ls_NickName = loo_JResp.StringOf("value[i].nickName")
    ls_Surname = loo_JResp.StringOf("value[i].surname")
    ls_Title = loo_JResp.StringOf("value[i].title")
    ls_YomiGivenName = loo_JResp.StringOf("value[i].yomiGivenName")
    ls_YomiSurname = loo_JResp.StringOf("value[i].yomiSurname")
    ls_YomiCompanyName = loo_JResp.StringOf("value[i].yomiCompanyName")
    ls_Generation = loo_JResp.StringOf("value[i].generation")
    ls_JobTitle = loo_JResp.StringOf("value[i].jobTitle")
    ls_CompanyName = loo_JResp.StringOf("value[i].companyName")
    ls_Department = loo_JResp.StringOf("value[i].department")
    ls_OfficeLocation = loo_JResp.StringOf("value[i].officeLocation")
    ls_Profession = loo_JResp.StringOf("value[i].profession")
    ls_BusinessHomePage = loo_JResp.StringOf("value[i].businessHomePage")
    ls_AssistantName = loo_JResp.StringOf("value[i].assistantName")
    ls_Manager = loo_JResp.StringOf("value[i].manager")
    ls_MobilePhone = loo_JResp.StringOf("value[i].mobilePhone")
    ls_SpouseName = loo_JResp.StringOf("value[i].spouseName")
    ls_PersonalNotes = loo_JResp.StringOf("value[i].personalNotes")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("value[i].categories")
    do while j < li_Count_j
        loo_JResp.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("value[i].imAddresses")
    do while j < li_Count_j
        loo_JResp.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("value[i].homePhones")
    do while j < li_Count_j
        loo_JResp.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("value[i].businessPhones")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("value[i].businessPhones[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("value[i].children")
    do while j < li_Count_j
        loo_JResp.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("value[i].emailAddresses")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_Name = loo_JResp.StringOf("value[i].emailAddresses[j].name")
        ls_Address = loo_JResp.StringOf("value[i].emailAddresses[j].address")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Http
destroy loo_JsonToken
destroy loo_SbJson
destroy loo_JResp