Sample code for 30+ languages & platforms
Xojo Plugin Requires Chilkat v11.0.0+

Constant Contact V3: Find a contact by email address

See more Constant Contact Examples

Look up an exact email address across contact states, including deleted contacts. Pass the address as a query parameter so a literal plus sign survives URL encoding. Read the stored contact ID, email permission, and deletion marker. An empty contacts array means no match. Authorize the app first and use the same credential store.

Constant Contact developer guide

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim vault As New Chilkat.Secrets
vault.Location = "local_manager"
vault.AutoSplit = True
Dim entry As New Chilkat.JsonObject
success = entry.UpdateString("appName","ConstantContactV3")
success = entry.UpdateString("service","OAuth2")
success = entry.UpdateString("username","my-account")
Dim tokens As New Chilkat.JsonObject
Dim loaded As Boolean
loaded = vault.GetSecretJson(entry,tokens)
If (loaded <> True) Then
    System.DebugLog("Run the desktop authorization example using this account and store.")
    Return
End If

If (tokens.JsonTypeOf("access_token") <> 1) Then
    System.DebugLog("The saved authorization has no access token.")
    Return
End If

Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.AuthToken = tokens.StringOf("access_token")
Dim resp As New Chilkat.HttpResponse

Dim query As New Chilkat.HttpRequest
query.HttpVerb = "GET"
query.AddParam "email","reader+newsletter@example.com"
query.AddParam "status","all"
success = http.HttpReq("https://api.cc.email/v3/contacts",query,resp)
If ((success <> True) Or (resp.StatusCode <> 200)) Then
    System.DebugLog("Expected HTTP 200. Received " + Str(resp.StatusCode))
    If (resp.StatusCode = 401) Then
        System.DebugLog("Refresh the saved access token or authorize again.")
    End If

    Return
End If

Dim reply As New Chilkat.JsonObject
success = reply.Load(resp.BodyStr)
If (success <> True) Then
    System.DebugLog("Expected a JSON response.")
    Return
End If

Dim count As Int32
count = reply.SizeOfArray("contacts")
If (count < 0) Then
    System.DebugLog("The reply contained no contacts array.")
    Return
End If

If (count = 0) Then
    System.DebugLog("No contact has that email address.")
    Return
End If

Dim i As Int32
i = 0
While (i < count)
    reply.I = i
    System.DebugLog("Contact ID: " + reply.StringOf("contacts[i].contact_id"))
    System.DebugLog("Email permission: " + reply.StringOf("contacts[i].email_address.permission_to_send"))
    If (reply.JsonTypeOf("contacts[i].deleted_at") = 1) Then
        System.DebugLog("Deleted at: " + reply.StringOf("contacts[i].deleted_at"))
    End If

    i = i + 1
Wend