VBScript Requires Chilkat v11.0.0+
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set vault = CreateObject("Chilkat.Secrets")
vault.Location = "local_manager"
vault.AutoSplit = 1
set entry = CreateObject("Chilkat.JsonObject")
success = entry.UpdateString("appName","ConstantContactV3")
success = entry.UpdateString("service","OAuth2")
success = entry.UpdateString("username","my-account")
set tokens = CreateObject("Chilkat.JsonObject")
loaded = vault.GetSecretJson(entry,tokens)
If (loaded <> 1) Then
outFile.WriteLine("Run the desktop authorization example using this account and store.")
WScript.Quit
End If
If (tokens.JsonTypeOf("access_token") <> 1) Then
outFile.WriteLine("The saved authorization has no access token.")
WScript.Quit
End If
set http = CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.AuthToken = tokens.StringOf("access_token")
set resp = CreateObject("Chilkat.HttpResponse")
set query = CreateObject("Chilkat.HttpRequest")
query.HttpVerb = "GET"
query.AddParam "email","reader+newsletter@example.com"
query.AddParam "status","all"
success = http.HttpReq("https://api.cc.email/v3/contacts",query,resp)
If ((success <> 1) Or (resp.StatusCode <> 200)) Then
outFile.WriteLine("Expected HTTP 200. Received " & resp.StatusCode)
If (resp.StatusCode = 401) Then
outFile.WriteLine("Refresh the saved access token or authorize again.")
End If
WScript.Quit
End If
set reply = CreateObject("Chilkat.JsonObject")
success = reply.Load(resp.BodyStr)
If (success <> 1) Then
outFile.WriteLine("Expected a JSON response.")
WScript.Quit
End If
count = reply.SizeOfArray("contacts")
If (count < 0) Then
outFile.WriteLine("The reply contained no contacts array.")
WScript.Quit
End If
If (count = 0) Then
outFile.WriteLine("No contact has that email address.")
WScript.Quit
End If
i = 0
Do While (i < count)
reply.I = i
outFile.WriteLine("Contact ID: " & reply.StringOf("contacts[i].contact_id"))
outFile.WriteLine("Email permission: " & reply.StringOf("contacts[i].email_address.permission_to_send"))
If (reply.JsonTypeOf("contacts[i].deleted_at") = 1) Then
outFile.WriteLine("Deleted at: " & reply.StringOf("contacts[i].deleted_at"))
End If
i = i + 1
Loop
outFile.Close