Sample code for 30+ languages & platforms
Lianja

Constant Contact - Get Contact by Email Address

See more Constant Contact Examples

Get the contact details for a given email address.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loHttp = createobject("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

loHttp.SetRequestHeader("Accept","application/json")
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
loHttp.AuthToken = "ACCESS_TOKEN"
loHttp.SetRequestHeader("Postman-Token","98980ee6-b99f-41a9-9a7a-3b5651d2ea7f")
loHttp.SetRequestHeader("Content-Type","application/json")
loHttp.SetRequestHeader("cache-control","no-cache")

loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb("https://api.cc.email/v3/contacts?email=danipper@example.com&status=all",loSbResponseBody)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    release loHttp
    release loSbResponseBody
    return
endif

loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    release loHttp
    release loSbResponseBody
    release loJResp
    return
endif

// 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

i = 0
lnCount_i = loJResp.SizeOfArray("contacts")
do while i < lnCount_i
    loJResp.I = i
    lcContact_id = loJResp.StringOf("contacts[i].contact_id")
    lcEmail_addressAddress = loJResp.StringOf("contacts[i].email_address.address")
    lcEmail_addressPermission_to_send = loJResp.StringOf("contacts[i].email_address.permission_to_send")
    lcEmail_addressCreated_at = loJResp.StringOf("contacts[i].email_address.created_at")
    lcEmail_addressUpdated_at = loJResp.StringOf("contacts[i].email_address.updated_at")
    lcEmail_addressOpt_in_source = loJResp.StringOf("contacts[i].email_address.opt_in_source")
    lcEmail_addressOpt_in_date = loJResp.StringOf("contacts[i].email_address.opt_in_date")
    lcEmail_addressConfirm_status = loJResp.StringOf("contacts[i].email_address.confirm_status")
    lcFirst_name = loJResp.StringOf("contacts[i].first_name")
    lcLast_name = loJResp.StringOf("contacts[i].last_name")
    lcJob_title = loJResp.StringOf("contacts[i].job_title")
    lcCompany_name = loJResp.StringOf("contacts[i].company_name")
    lnBirthday_month = loJResp.IntOf("contacts[i].birthday_month")
    lnBirthday_day = loJResp.IntOf("contacts[i].birthday_day")
    lcAnniversary = loJResp.StringOf("contacts[i].anniversary")
    lcCreate_source = loJResp.StringOf("contacts[i].create_source")
    lcCreated_at = loJResp.StringOf("contacts[i].created_at")
    lcUpdated_at = loJResp.StringOf("contacts[i].updated_at")
    i = i + 1
enddo


release loHttp
release loSbResponseBody
release loJResp