Go Requires Chilkat v11.0.0+
Go
Constant Contact V3: Find a contact list by name
See more Constant Contact Examples
Start with the full list name from the Constant Contact account. Read its list_id and the number of active, mailable contacts. Use the ID for list membership operations or campaign targeting. This lookup requires contact_data.
Authorize the application using the same account and credential store.
Constant Contact developer guide
Chilkat Go Downloads
success := false
// Assumes Chilkat is unlocked. See Global Unlock Sample.
vault := chilkat.NewSecrets()
vault.SetLocation("local_manager")
vault.SetAutoSplit(true)
entry := chilkat.NewJsonObject()
entry.UpdateString("appName","ConstantContactV3")
entry.UpdateString("service","OAuth2")
entry.UpdateString("username","my-account")
tokens := chilkat.NewJsonObject()
loaded := vault.GetSecretJson(entry,tokens)
if loaded != true {
fmt.Println("Run the desktop authorization example using this account and store.")
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
return
}
if tokens.JsonTypeOf("access_token") != 1 {
fmt.Println("The saved authorization has no access token.")
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
return
}
http := chilkat.NewHttp()
http.SetRequireSslCertVerify(true)
http.SetAuthToken(tokens.StringOf("access_token"))
resp := chilkat.NewHttpResponse()
// Use the full display name. AddParam encodes spaces and punctuation.
listName := "Workshop announcements"
query := chilkat.NewHttpRequest()
query.SetHttpVerb("GET")
query.AddParam("name",listName)
query.AddParam("status","active")
query.AddParam("include_membership_count","active")
success = http.HttpReq("https://api.cc.email/v3/contact_lists",query,resp)
if (success != true) && (resp.StatusCode() <= 0) {
fmt.Println("Look up list: HTTP request failed.")
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
query.DisposeHttpRequest()
return
}
if (success != true) || (resp.StatusCode() != 200) {
fmt.Println("Look up list: HTTP ", resp.StatusCode(), " ", resp.BodyStr())
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
query.DisposeHttpRequest()
return
}
matches := chilkat.NewJsonObject()
success = matches.Load(resp.BodyStr())
if success != true {
fmt.Println("Expected a JSON object in the response.")
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
query.DisposeHttpRequest()
matches.DisposeJsonObject()
return
}
if matches.SizeOfArray("lists") == 0 {
fmt.Println("No active email list named ", listName)
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
query.DisposeHttpRequest()
matches.DisposeJsonObject()
return
}
if (matches.SizeOfArray("lists") != 1) || (matches.StringOfEquals("lists[0].name",listName,true) != true) {
fmt.Println("Expected one exact list name.")
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
query.DisposeHttpRequest()
matches.DisposeJsonObject()
return
}
listId := matches.StringOf("lists[0].list_id")
if *listId == "" {
fmt.Println("Missing list ID.")
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
query.DisposeHttpRequest()
matches.DisposeJsonObject()
return
}
fmt.Println(listName, " | List ID: ", *listId, " | Mailable contacts: ", matches.IntOf("lists[0].membership_count"))
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
query.DisposeHttpRequest()
matches.DisposeJsonObject()