Tcl
Tcl
Constant Contact - Get Contact by Email Address
See more Constant Contact Examples
Get the contact details for a given email address.Chilkat Tcl Downloads
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?email=new_contact_email&status=all' \
# -H 'Accept: application/json' \
# -H 'Authorization: Bearer ACCESS_TOKEN' \
# -H 'Content-Type: application/json' \
# -H 'Postman-Token: 98980ee6-b99f-41a9-9a7a-3b5651d2ea7f' \
# -H 'cache-control: no-cache'
# Use the following online tool to generate HTTP code from a CURL command
# Convert a cURL Command to HTTP Source Code
CkHttp_SetRequestHeader $http "Accept" "application/json"
# Adds the "Authorization: Bearer ACCESS_TOKEN" header.
CkHttp_put_AuthToken $http "ACCESS_TOKEN"
CkHttp_SetRequestHeader $http "Postman-Token" "98980ee6-b99f-41a9-9a7a-3b5651d2ea7f"
CkHttp_SetRequestHeader $http "Content-Type" "application/json"
CkHttp_SetRequestHeader $http "cache-control" "no-cache"
set sbResponseBody [new_CkStringBuilder]
set success [CkHttp_QuickGetSb $http "https://api.cc.email/v3/contacts?email=danipper@example.com&status=all" $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": "8207fa8e-13dd-11eb-8a66-fa163e37306a",
# "email_address": {
# "address": "danipper@example.com",
# "permission_to_send": "implicit",
# "created_at": "2020-10-21T20:39:25Z",
# "updated_at": "2020-10-21T20:39:25Z",
# "opt_in_source": "Account",
# "opt_in_date": "2020-10-21T20:39:25Z",
# "confirm_status": "off"
# },
# "first_name": "David",
# "last_name": "Nipper",
# "job_title": "Musician",
# "company_name": "Acme Corp.",
# "birthday_month": 11,
# "birthday_day": 24,
# "anniversary": "2006-11-15",
# "create_source": "Account",
# "created_at": "2020-10-21T20:39:25Z",
# "updated_at": "2020-10-21T20:39:25Z"
# }
# ]
# }
# 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 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 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 i [expr $i + 1]
}
delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp