PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
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 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
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")
// Obtain the selected contact ID from the email lookup example.
loo_Http.SetUrlVar("contactId","CONTACT_ID")
li_Success = loo_Http.HttpNoBody("DELETE","https://api.cc.email/v3/contacts/{$contactId}",loo_Resp)
if loo_Resp.StatusCode = 404 then
Write-Debug "Contact ID not found in this account."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
return
end if
if (li_Success <> 1) OR (loo_Resp.StatusCode <> 204) then
Write-Debug "Expected HTTP 204. 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
return
end if
Write-Debug "Contact deleted and list memberships removed."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp