How can I export mailing list contacts via API call? | XM Community
Solved

How can I export mailing list contacts via API call?

  • 12 September 2019
  • 4 replies
  • 132 views

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?
icon

Best answer by JeremyK 13 September 2019, 17:03

View original

4 replies

Userlevel 5
Badge +7
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.
Userlevel 2
Badge +8
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.
Badge +1

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, [Headers=[#"X-API-TOKEN"="???"]])),
  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]  each [i=[i]+1, res = FnGetOnePage([res][Next])],
  each [res][Data])
in
  GeneratedList


Userlevel 5
Badge +11

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