Sample code for 30+ languages & platforms
Go

Outlook List Contacts

See more Outlook Contact Examples

List Outlook Contacts

Chilkat Go Downloads

Go
    success := false

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

    http := chilkat.NewHttp()

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

    jsonToken := chilkat.NewJsonObject()
    success = jsonToken.LoadFile("qa_data/tokens/outlookContacts.json")
    if success == false {
        fmt.Println(jsonToken.LastErrorText())
        http.DisposeHttp()
        jsonToken.DisposeJsonObject()
        return
    }

    http.SetAuthToken(jsonToken.StringOf("access_token"))

    // Send the following GET:

    // GET https://graph.microsoft.com/v1.0/me/contacts
    sbJson := chilkat.NewStringBuilder()
    success = http.QuickGetSb("https://graph.microsoft.com/v1.0/me/contacts",sbJson)
    if success == false {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        jsonToken.DisposeJsonObject()
        sbJson.DisposeStringBuilder()
        return
    }

    statusCode := http.LastStatus()
    fmt.Println("Response status code = ", statusCode)

    if statusCode != 200 {
        fmt.Println(*sbJson.GetAsString())
        fmt.Println("Failed.")
        http.DisposeHttp()
        jsonToken.DisposeJsonObject()
        sbJson.DisposeStringBuilder()
        return
    }

    jResp := chilkat.NewJsonObject()
    jResp.LoadSb(sbJson)
    jResp.SetEmitCompact(false)
    fmt.Println(*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": {}
    //     },
    // ...
    //   ]
    // }

    var odata_etag *string = new(string)
    var id *string = new(string)
    var createdDateTime *string = new(string)
    var lastModifiedDateTime *string = new(string)
    var changeKey *string = new(string)
    var parentFolderId *string = new(string)
    var birthday *string = new(string)
    var fileAs *string = new(string)
    var displayName *string = new(string)
    var givenName *string = new(string)
    var initials *string = new(string)
    var middleName *string = new(string)
    var nickName *string = new(string)
sur    var name *string = new(string)
    var title *string = new(string)
    var yomiGivenName *string = new(string)
yomiSur    var name *string = new(string)
    var yomiCompanyName *string = new(string)
    var generation *string = new(string)
    var jobTitle *string = new(string)
    var companyName *string = new(string)
    var department *string = new(string)
    var officeLocation *string = new(string)
    var profession *string = new(string)
    var businessHomePage *string = new(string)
    var assistantName *string = new(string)
    var manager *string = new(string)
    var mobilePhone *string = new(string)
    var spouseName *string = new(string)
    var personalNotes *string = new(string)
    var j int
    var count_j int
    var strVal *string = new(string)
    var name *string = new(string)
    var address *string = new(string)

    odata_context := jResp.StringOf("\"@odata.context\"")
    i := 0
    count_i := jResp.SizeOfArray("value")
    for i < count_i {
        jResp.SetI(i)
        odata_etag = jResp.StringOf("value[i].\"@odata.etag\"")
        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")
        for j < count_j {
            jResp.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("value[i].imAddresses")
        for j < count_j {
            jResp.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("value[i].homePhones")
        for j < count_j {
            jResp.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("value[i].businessPhones")
        for j < count_j {
            jResp.SetJ(j)
            strVal = jResp.StringOf("value[i].businessPhones[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("value[i].children")
        for j < count_j {
            jResp.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("value[i].emailAddresses")
        for j < count_j {
            jResp.SetJ(j)
            name = jResp.StringOf("value[i].emailAddresses[j].name")
            address = jResp.StringOf("value[i].emailAddresses[j].address")
            j = j + 1
        }

        i = i + 1
    }


    http.DisposeHttp()
    jsonToken.DisposeJsonObject()
    sbJson.DisposeStringBuilder()
    jResp.DisposeJsonObject()