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

Constant Contact V3: Create a contact list

See more Constant Contact Examples

Create a list with a unique name and a short description. Save the returned list_id with your application’s list record and use it in the membership examples. The new list starts empty. 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 body As New Chilkat.JsonObject
success = body.UpdateString("name","Workshop announcements")
success = body.UpdateString("description","People who requested workshop updates")
success = http.HttpJson("POST","https://api.cc.email/v3/contact_lists",body,"application/json",resp)
If (resp.StatusCode = 409) Then
    System.DebugLog("A conflicting list already exists. Check the existing lists before retrying.")
    Return
End If

If ((success <> True) Or (resp.StatusCode <> 201)) Then
    System.DebugLog("Expected HTTP 201. 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 created As New Chilkat.JsonObject
success = created.Load(resp.BodyStr)
If (success <> True) Then
    System.DebugLog("Expected a JSON response.")
    Return
End If

If ((created.JsonTypeOf("list_id") <> 1) Or (created.StringOfEquals("list_id","",True) = True)) Then
    System.DebugLog("Missing list_id in the response.")
    Return
End If

System.DebugLog("Created " + created.StringOf("name") + ". List ID: " + created.StringOf("list_id"))