Go Requires Chilkat v11.0.0+
Go
Constant Contact V3: Delete a contact by ID
See more Constant Contact Examples
Use the ID of the contact selected for deletion. Deletion removes all list memberships and sets the deletion timestamp. Unsubscribing is a separate operation that changes permission to send. A successful delete returns HTTP 204 with an empty body. To bring the record back, see Restore a deleted contact. Authorize the app first and use the same 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()
// Obtain the selected contact ID from the email lookup example.
http.SetUrlVar("contactId","CONTACT_ID")
success = http.HttpNoBody("DELETE","https://api.cc.email/v3/contacts/{$contactId}",resp)
if resp.StatusCode() == 404 {
fmt.Println("Contact ID not found in this account.")
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
return
}
if (success != true) || (resp.StatusCode() != 204) {
fmt.Println("Expected HTTP 204. Received ", resp.StatusCode())
if resp.StatusCode() == 401 {
fmt.Println("Refresh the saved access token or authorize again.")
}
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()
return
}
fmt.Println("Contact deleted and list memberships removed.")
vault.DisposeSecrets()
entry.DisposeJsonObject()
tokens.DisposeJsonObject()
http.DisposeHttp()
resp.DisposeHttpResponse()