Sample code for 30+ languages & platforms
Tcl

Constant Contact - View List Members

See more Constant Contact Examples

View the list membership by making a GET call to the Contact Collection endpointl

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set http [new_CkHttp]

# Implements the following CURL command:

# curl -X GET \
#   'https://api.cc.email/v3/contacts?lists={list_id},{list_id2}' \
#   -H 'accept: application/json' \
#   -H 'authorization: Bearer {access_token}' \
#   -H 'cache-control: no-cache' \
#   -H 'content-type: application/json'

# Use the following online tool to generate HTTP code from a CURL command
# Convert a cURL Command to HTTP Source Code

CkHttp_SetRequestHeader $http "content-type" "application/json"
# Adds the "Authorization: Bearer ACCESS_TOKEN" header.
CkHttp_put_AuthToken $http "ACCESS_TOKEN"
CkHttp_SetRequestHeader $http "cache-control" "no-cache"
CkHttp_SetRequestHeader $http "accept" "application/json"

set sbResponseBody [new_CkStringBuilder]

set success [CkHttp_QuickGetSb $http "https://api.cc.email/v3/contacts?lists={list_id},{list_id2}" $sbResponseBody]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttp_get_LastStatus $http]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttp_lastHeader $http]
    puts "Failed."
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

# Sample JSON response:
# (Sample code for parsing the JSON response is shown below)

# {
#   "contacts": [
#     {
#       "contact_id": "{contact_id}",
#       "email_address": {
#         "address": "dprice@example.com",
#         "permission_to_send": "implicit",
#         "created_at": "2013-11-26T15:45:42-05:00",
#         "updated_at": "2013-11-26T15:45:42-05:00",
#         "opt_in_source": "Account",
#         "opt_in_date": "2013-11-26T15:45:42-05:00",
#         "confirm_status": "off"
#       },
#       "first_name": "David",
#       "last_name": "Price",
#       "update_source": "Account",
#       "create_source": "Account",
#       "created_at": "2013-11-26T15:45:42-05:00",
#       "updated_at": "2017-09-06T15:48:31-04:00"
#     },
#     {
#       "contact_id": "{contact_id}",
#       "email_address": {
#         "address": "jprice@example.com",
#         "permission_to_send": "implicit",
#         "created_at": "2013-11-26T15:45:50-05:00",
#         "updated_at": "2013-11-26T15:45:50-05:00",
#         "opt_in_source": "Account",
#         "opt_in_date": "2013-11-26T15:45:50-05:00",
#         "confirm_status": "off"
#       },
#       "first_name": "Jennifer",
#       "last_name": "Price",
#       "create_source": "Account",
#       "created_at": "2013-11-26T15:45:50-05:00",
#       "updated_at": "2013-11-26T15:45:50-05:00"
#     },
#     {
#       "contact_id": "{contact_id}",
#       "email_address": {
#         "address": "joe.jones@example.com",
#         "permission_to_send": "implicit",
#         "created_at": "2017-11-06T15:35:30-05:00",
#         "updated_at": "2017-11-06T15:35:30-05:00",
#         "opt_in_source": "Account",
#         "opt_in_date": "2017-11-06T15:35:30-05:00",
#         "confirm_status": "off"
#       },
#       "first_name": "Joe",
#       "last_name": "Jones",
#       "job_title": "Chief Innovation Officer",
#       "company_name": "RelativeGravity, Inc.",
#       "birthday_month": 11,
#       "birthday_day": 24,
#       "anniversary": "2006-11-15",
#       "create_source": "Account",
#       "created_at": "2017-11-06T15:35:30-05:00",
#       "updated_at": "2017-11-06T15:35:30-05:00"
#     },
#     {
#       "contact_id": "{contact_id}",
#       "email_address": {
#         "address": "mmiller@example.com",
#         "permission_to_send": "implicit",
#         "created_at": "2013-11-26T15:46:04-05:00",
#         "updated_at": "2013-11-26T15:46:04-05:00",
#         "opt_in_source": "Account",
#         "opt_in_date": "2013-11-26T15:46:04-05:00",
#         "confirm_status": "off"
#       },
#       "first_name": "Mike",
#       "last_name": "Miller.",
#       "create_source": "Account",
#       "created_at": "2013-11-26T15:46:04-05:00",
#       "updated_at": "2013-11-26T15:46:04-05:00"
#     },
#     {
#       "contact_id": "{contact_id}",
#       "email_address": {
#         "address": "sheryl.kavanaugh@example.com",
#         "permission_to_send": "implicit",
#         "created_at": "2013-11-26T15:46:10-05:00",
#         "updated_at": "2013-11-26T15:46:10-05:00",
#         "opt_in_source": "Account",
#         "opt_in_date": "2013-11-26T15:46:10-05:00",
#         "confirm_status": "off"
#       },
#       "first_name": "Sheryl",
#       "last_name": "Kavanaugh",
#       "create_source": "Account",
#       "created_at": "2013-11-26T15:46:10-05:00",
#       "updated_at": "2013-11-26T15:46:10-05:00"
#     }
#   ]
# }

# Sample code for parsing the JSON response...
# Use the following online tool to generate parsing code from sample JSON:
# Generate Parsing Code from JSON

set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "contacts"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set contact_id [CkJsonObject_stringOf $jResp "contacts[i].contact_id"]
    set email_addressAddress [CkJsonObject_stringOf $jResp "contacts[i].email_address.address"]
    set email_addressPermission_to_send [CkJsonObject_stringOf $jResp "contacts[i].email_address.permission_to_send"]
    set email_addressCreated_at [CkJsonObject_stringOf $jResp "contacts[i].email_address.created_at"]
    set email_addressUpdated_at [CkJsonObject_stringOf $jResp "contacts[i].email_address.updated_at"]
    set email_addressOpt_in_source [CkJsonObject_stringOf $jResp "contacts[i].email_address.opt_in_source"]
    set email_addressOpt_in_date [CkJsonObject_stringOf $jResp "contacts[i].email_address.opt_in_date"]
    set email_addressConfirm_status [CkJsonObject_stringOf $jResp "contacts[i].email_address.confirm_status"]
    set first_name [CkJsonObject_stringOf $jResp "contacts[i].first_name"]
    set last_name [CkJsonObject_stringOf $jResp "contacts[i].last_name"]
    set update_source [CkJsonObject_stringOf $jResp "contacts[i].update_source"]
    set create_source [CkJsonObject_stringOf $jResp "contacts[i].create_source"]
    set created_at [CkJsonObject_stringOf $jResp "contacts[i].created_at"]
    set updated_at [CkJsonObject_stringOf $jResp "contacts[i].updated_at"]
    set job_title [CkJsonObject_stringOf $jResp "contacts[i].job_title"]
    set company_name [CkJsonObject_stringOf $jResp "contacts[i].company_name"]
    set birthday_month [CkJsonObject_IntOf $jResp "contacts[i].birthday_month"]
    set birthday_day [CkJsonObject_IntOf $jResp "contacts[i].birthday_day"]
    set anniversary [CkJsonObject_stringOf $jResp "contacts[i].anniversary"]
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp