401 error for contact imports | XM Community
Skip to main content
Solved

401 error for contact imports

  • August 18, 2021
  • 1 reply
  • 150 views

I am trying to import contacts via api using python. But I am getting 401 error as :-
{"meta":{"httpStatus":"401 - Unauthorized","error":{"errorMessage":"No default directory found for brand: xyz.","errorCode":"xyz"},"requestId":"xyz"}}
My code is given below :-
import requests
import json

dict_Contacts = [
 {
  "firstName": "xyz",
  "lastName": "xyz",
  "email": "xyz@xyz.com",
  "language": "xyz",
  "unsubscribed":1, 
  "externalReference":"xyz",
  "embeddedData": {"ExampleField1":"xyz", "ExampleField2":"xyz"}
 }
]

Token = 'My_Token'
MailingListID = 'My_Mailing_List'
dataCenter = 'My_Data_Center'

url = "https://{0}.qualtrics.com/API/v3/mailinglists/{1}/contactimports/".format(dataCenter, MailingListID)
headers = {
  'x-api-token': Token,
  'contentType':'application/json'
  } 
json_string = json.dumps(dict_Contacts)
files = {'contacts': ('contacts', json_string, 'application/json')}
request = requests.post(url, headers=headers, json={'contacts':dict_Contacts})
print(request.text)

My token and path are correct. Can anybody please tell me what exactly the error means? (as No default directory found for brand) and how to resolve this issue.

Best answer by NiC

Hi Rasika,
The error hints that your account has XM Directory. The above API call you are doing is not supported of XM directory users(as XM directory users can have multiple directories).
You can use this call to import contacts into XM directory - https://api.qualtrics.com/api-reference/reference/contactImports.json/paths/~1directories~1%7BdirectoryId%7D~1mailinglists~1%7BmailingListId%7D~1transactioncontacts/post


1 reply

NiC
QPN Level 5 ●●●●●
Forum|alt.badge.img+27
  • QPN Level 5 ●●●●●
  • Answer
  • August 18, 2021

Hi Rasika,
The error hints that your account has XM Directory. The above API call you are doing is not supported of XM directory users(as XM directory users can have multiple directories).
You can use this call to import contacts into XM directory - https://api.qualtrics.com/api-reference/reference/contactImports.json/paths/~1directories~1%7BdirectoryId%7D~1mailinglists~1%7BmailingListId%7D~1transactioncontacts/post