Dart Requires Chilkat v11.0.0+
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
final vault = CkSecrets();
vault.location = 'local_manager';
vault.autoSplit = true;
final entry = CkJsonObject();
entry.updateString('appName', 'ConstantContactV3');
entry.updateString('service', 'OAuth2');
entry.updateString('username', 'my-account');
final tokens = CkJsonObject();
try {
vault.getSecretJson(entry, tokens);
} on ChilkatException {
print('Run the desktop authorization example using this account and store.');
return;
}
if (tokens.jsonTypeOf('access_token') != 1) {
print('The saved authorization has no access token.');
return;
}
final http = CkHttp();
http.requireSslCertVerify = true;
http.authToken = tokens.stringOf('access_token');
final resp = CkHttpResponse();
// Obtain the selected contact ID from the email lookup example.
http.setUrlVar('contactId', 'CONTACT_ID');
success = true;
try {
http.httpNoBody('DELETE', 'https://api.cc.email/v3/contacts/{\$contactId}', resp);
} on ChilkatException {
success = false;
}
if (resp.statusCode == 404) {
print('Contact ID not found in this account.');
return;
}
if ((!success) || (resp.statusCode != 204)) {
print('Expected HTTP 204. Received ${resp.statusCode}');
if (resp.statusCode == 401) {
print('Refresh the saved access token or authorize again.');
}
return;
}
print('Contact deleted and list memberships removed.');
}