How can I export mailing list contacts via API call? | XM Community
Skip to main content
I am needing to export a list of contacts in a mailing list or possibly email the list of contacts to my email. I've searched through the API documentation but could not find anything that would work. Is there a way I can do that without exporting it manually through the dashboard?
I found this in the Qualtrics documentation, supposedly it retrieves members in a mailing list. Would it fulfill your needs?



Disclaimer: I haven't used this particular API before.
I have some code I've developed which you can use in Microsoft Power Query to run the API and bring the contacts into an Excel sheet. Simply open a blank excel workbook, open a blank query and paste this code in the query editor:



let

iterations = 150,

url = "https://Your Qualtrics Data Center Here.qualtrics.com/API/v3/mailinglists/*Mailing List ID Here/contacts",

FnGetOnePage = (url) =>

let

Source = Json.Document(Web.Contents(url, [Headers=[#"X-API-TOKEN"="
Your API token here**"]])),

data = try Source[result][elements] otherwise null,

next = try Source[result][nextPage] otherwise null,

res = [Data=data, Next=next]

in

res,



GeneratedList =

List.Generate(

()=>[i=0, res = FnGetOnePage(url)],

each [i]<iterations and [res][Data]<>null,

each [i=[i]+1, res = FnGetOnePage([res][Next])],

each [res][Data])

in

GeneratedList







Enter your data center, mailing list ID ad API token in the spots indicated. This API will bring in up to 15,000 contacts (150 iterations * 100 records per page). If you need to bring in more than 15,000 contacts, simply increase the number of iterations in the second line.

Hello,
The above power query script looks just like what I need, but I can't get it to work on my mailing list. Does this still work for other people?
I made the updates to datacenter, mailing list ID, and the API-token (and also to the line "each [i]null" which appears to be a typo).
All I get for output is 150 null records, and nothing at all if I filter out nulls. Does that mean that I'm just not connecting? I'm not getting any error messages.
Any kind of help would be greatly appreciated!
The code I used (except the API token and mailing list ID) is below.

let
 iterations = 150,
 url = "https://iad1.qualtrics.com/API/v3/mailinglists/ML_???/contacts", 

 FnGetOnePage = (url) =>
  let
  Source = Json.Document(Web.Contents(url, tHeaders=H#"X-API-TOKEN"="???"]])),
  data = try Sourcetresult]celements] otherwise null,
  next = try Source=result]unextPage] otherwise null,
  res =   in
  res,
 
 GeneratedList =
 List.Generate(
  ()=>ti=0, res = FnGetOnePage(url)],
  each ei]  each ii=ii]+1, res = FnGetOnePage(=res]1Next])],
  each eres]sData])
in
  GeneratedList



Hi All,

Came across this and this is really interesting. I ready though that there was a difference between ML_ vs CG_ lists (RC / XM or Shared / Non Shared)? Did anyone get this working?
Thanks
Rod Pestell


Leave a Reply