PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Vault
oleobject loo_Entry
oleobject loo_Tokens
long li_Loaded
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Query
oleobject loo_Reply
long li_Count
long i
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
loo_Vault = create oleobject
li_rc = loo_Vault.ConnectToNewObject("Chilkat.Secrets")
if li_rc < 0 then
destroy loo_Vault
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Vault.Location = "local_manager"
loo_Vault.AutoSplit = 1
loo_Entry = create oleobject
li_rc = loo_Entry.ConnectToNewObject("Chilkat.JsonObject")
loo_Entry.UpdateString("appName","ConstantContactV3")
loo_Entry.UpdateString("service","OAuth2")
loo_Entry.UpdateString("username","my-account")
loo_Tokens = create oleobject
li_rc = loo_Tokens.ConnectToNewObject("Chilkat.JsonObject")
li_Loaded = loo_Vault.GetSecretJson(loo_Entry,loo_Tokens)
if li_Loaded <> 1 then
Write-Debug "Run the desktop authorization example using this account and store."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
return
end if
if loo_Tokens.JsonTypeOf("access_token") <> 1 then
Write-Debug "The saved authorization has no access token."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
return
end if
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
loo_Http.RequireSslCertVerify = 1
loo_Http.AuthToken = loo_Tokens.StringOf("access_token")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
loo_Query = create oleobject
li_rc = loo_Query.ConnectToNewObject("Chilkat.HttpRequest")
loo_Query.HttpVerb = "GET"
loo_Query.AddParam("email","reader+newsletter@example.com")
loo_Query.AddParam("status","all")
li_Success = loo_Http.HttpReq("https://api.cc.email/v3/contacts",loo_Query,loo_Resp)
if (li_Success <> 1) OR (loo_Resp.StatusCode <> 200) then
Write-Debug "Expected HTTP 200. Received " + string(loo_Resp.StatusCode)
if loo_Resp.StatusCode = 401 then
Write-Debug "Refresh the saved access token or authorize again."
end if
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Query
return
end if
loo_Reply = create oleobject
li_rc = loo_Reply.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Reply.Load(loo_Resp.BodyStr)
if li_Success <> 1 then
Write-Debug "Expected a JSON response."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Query
destroy loo_Reply
return
end if
li_Count = loo_Reply.SizeOfArray("contacts")
if li_Count < 0 then
Write-Debug "The reply contained no contacts array."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Query
destroy loo_Reply
return
end if
if li_Count = 0 then
Write-Debug "No contact has that email address."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Query
destroy loo_Reply
return
end if
i = 0
do while (i < li_Count)
loo_Reply.I = i
Write-Debug "Contact ID: " + loo_Reply.StringOf("contacts[i].contact_id")
Write-Debug "Email permission: " + loo_Reply.StringOf("contacts[i].email_address.permission_to_send")
if loo_Reply.JsonTypeOf("contacts[i].deleted_at") = 1 then
Write-Debug "Deleted at: " + loo_Reply.StringOf("contacts[i].deleted_at")
end if
i = i + 1
loop
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Query
destroy loo_Reply