Skip to content

Commit 7f3489d

Browse files
committed
24th Commit - Added and Updated the Update contact function
1 parent e11f88e commit 7f3489d

File tree

3 files changed

+25
-45
lines changed

3 files changed

+25
-45
lines changed
Binary file not shown.

QualtricsAPI/XM/xmdirectory.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,36 @@ def delete_contact(self, contact_id=None):
7070
url = base_url + f"/contacts/{contact_id}"
7171
request = r.delete(url, headers=headers)
7272
response = request.json()
73-
if content['meta']['httpStatus'] == '200 - OK':
73+
if response['meta']['httpStatus'] == '200 - OK':
7474
print(f'Your XM Contact"{contact_id}" has been deleted from the XM Directory.')
7575
except ContactIDError:
7676
'Hey there! It looks like the Contact ID that was entered is incorrect. It should begin with "CID_". Please try again.'
7777
return
7878

79+
def update_contact(self, contact_id=None, **kwargs):
80+
'''This method will update a contact from your XMDirectory.
81+
82+
:param contact_id: The unique id associated with each contact in the XM Directory.
83+
:type contact_id: str
84+
:return: Nothing, but prints if successful, and if there was an error.
85+
'''
86+
assert len(contact_id) == 19, 'Hey, the parameter for "contact_id" that was passed is the wrong length. It should have 19 characters.'
87+
assert contact_id[:4] == 'CID_', 'Hey there! It looks like the Contact ID that was entered is incorrect. It should begin with "CID_". Please try again.'
88+
89+
try:
90+
headers, base_url = self.header_setup()
91+
url = base_url + f"/contacts/{contact_id}"
92+
contact_data = {}
93+
for key, value in kwargs.items():
94+
contact_data.update({key: str(value)})
95+
request = r.put(url, json=contact_data, headers=headers)
96+
response = request.json()
97+
if response['meta']['httpStatus'] == '200 - OK':
98+
print(f'Your XM Contact"{contact_id}" has been updated in your XM Directory.')
99+
except ContactIDError:
100+
'Hey there! It looks like the Contact ID that was entered is incorrect. It should begin with "CID_". Please try again.'
101+
return
102+
79103
def list_contacts_in_directory(self, page_size=100, offset=0, to_df=True):
80104
'''This method will list the top-level information about the contacts in your XM Directory. Depending
81105
on the argument that you pass to the parameter 'to_df', the method will either return a Pandas DataFrame

info/Documentation_functions.txt

-44
This file was deleted.

0 commit comments

Comments
 (0)