DataFlex Requires Chilkat v11.0.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoVault
Variant vEntry
Handle hoEntry
Variant vTokens
Handle hoTokens
Boolean iLoaded
Handle hoHttp
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Get Create (RefClass(cComChilkatSecrets)) To hoVault
If (Not(IsComObjectCreated(hoVault))) Begin
Send CreateComObject of hoVault
End
Set ComLocation Of hoVault To "local_manager"
Set ComAutoSplit Of hoVault To True
Get Create (RefClass(cComChilkatJsonObject)) To hoEntry
If (Not(IsComObjectCreated(hoEntry))) Begin
Send CreateComObject of hoEntry
End
Get ComUpdateString Of hoEntry "appName" "ConstantContactV3" To iSuccess
Get ComUpdateString Of hoEntry "service" "OAuth2" To iSuccess
Get ComUpdateString Of hoEntry "username" "my-account" To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoTokens
If (Not(IsComObjectCreated(hoTokens))) Begin
Send CreateComObject of hoTokens
End
Get pvComObject of hoEntry to vEntry
Get pvComObject of hoTokens to vTokens
Get ComGetSecretJson Of hoVault vEntry vTokens To iLoaded
If (iLoaded <> True) Begin
Showln "Run the desktop authorization example using this account and store."
Procedure_Return
End
Get ComJsonTypeOf Of hoTokens "access_token" To iTemp1
If (iTemp1 <> 1) Begin
Showln "The saved authorization has no access token."
Procedure_Return
End
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComRequireSslCertVerify Of hoHttp To True
Get ComStringOf Of hoTokens "access_token" To sTemp1
Set ComAuthToken Of hoHttp To sTemp1
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
// Obtain the selected contact ID from the email lookup example.
Get ComSetUrlVar Of hoHttp "contactId" "CONTACT_ID" To iSuccess
Get pvComObject of hoResp to vResp
Get ComHttpNoBody Of hoHttp "DELETE" "https://api.cc.email/v3/contacts/{$contactId}" vResp To iSuccess
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 = 404) Begin
Showln "Contact ID not found in this account."
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
If ((iSuccess <> True) Or (iTemp1 <> 204)) Begin
Get ComStatusCode Of hoResp To iTemp1
Showln "Expected HTTP 204. Received " iTemp1
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 = 401) Begin
Showln "Refresh the saved access token or authorize again."
End
Procedure_Return
End
Showln "Contact deleted and list memberships removed."
End_Procedure