@@ -151,69 +151,60 @@ def add_contact(
151
151
152
152
# pylint: disable-next=unused-argument
153
153
def remove_contact (
154
- contact_identifier : str ,
154
+ value : str ,
155
+ identifier : t .Literal ["contact-id" , "email" , "mobile-number" ] = "email" ,
155
156
region : str = "r1" ,
156
157
auth : t .Optional [str ] = None ,
157
158
timeout : int = 30 ,
158
159
):
159
160
# pylint: disable=line-too-long
160
161
"""Remove an existing contact from Dotdigital.
161
162
162
- https://developer.dotdigital.com/reference/get-contact
163
- https://developer.dotdigital.com/reference/delete-contact
163
+ https://developer.dotdigital.com/reference/deletecontact-1
164
164
165
165
Args:
166
- contact_identifier: Either the contact id or email address of the contact.
166
+ value: The unique value to identify the contact. Note: Must be the same type as the identifier.
167
+ identifier: Field to use to uniquely identify the contact.
167
168
region: The Dotdigital region id your account belongs to e.g. r1, r2 or r3.
168
169
auth: The authorization header used to enable API access. If None, the value will be retrieved from the MAIL_AUTH environment variable.
169
170
timeout: Send timeout to avoid hanging.
170
171
171
172
Raises:
172
- AssertionError: If failed to get contact.
173
173
AssertionError: If failed to delete contact.
174
+
175
+ Returns:
176
+ A flag designating whether the contact was removed. True if the contact
177
+ was found, False if the contact was not found.
174
178
"""
175
179
# pylint: enable=line-too-long
176
180
177
181
if not settings .MAIL_ENABLED :
178
- logging .info ("Removed contact from DotDigital: %s" , contact_identifier )
179
- return
182
+ logging .info ("Removed contact from DotDigital: %s" , value )
183
+ return True
180
184
181
185
if auth is None :
182
186
auth = settings .MAIL_AUTH
183
187
184
188
response = requests .get (
185
189
# pylint: disable-next=line-too-long
186
- url = f"https://{ region } -api.dotdigital.com/v2/ contacts/{ contact_identifier } " ,
190
+ url = f"https://{ region } -api.dotdigital.com/contacts/v3/ { identifier } / { value } " ,
187
191
headers = {
188
192
"accept" : "application/json" ,
189
193
"authorization" : auth ,
190
194
},
191
195
timeout = timeout ,
192
196
)
193
197
194
- assert response .ok , (
195
- "Failed to get contact."
196
- f" Reason: { response .reason } ."
197
- f" Text: { response .text } ."
198
- )
199
-
200
- contact_id : int = response .json ()["id" ]
201
-
202
- response = requests .delete (
203
- url = f"https://{ region } -api.dotdigital.com/v2/contacts/{ contact_id } " ,
204
- headers = {
205
- "accept" : "application/json" ,
206
- "authorization" : auth ,
207
- },
208
- timeout = timeout ,
209
- )
198
+ not_found = response .status_code == 404
210
199
211
- assert response .ok , (
200
+ assert response .ok or not_found , (
212
201
"Failed to delete contact."
213
202
f" Reason: { response .reason } ."
214
203
f" Text: { response .text } ."
215
204
)
216
205
206
+ return not not_found
207
+
217
208
218
209
@dataclass
219
210
class EmailAttachment :
0 commit comments