Generate Custom Distribution Links
A custom distribution link generates a unique link for each person in a mailing list. Distribution links (Personal links) can be used for any channel. It allows the customer to generate a link from Qualtrics and send via their own platform. You can find more information about personal links at the support page for Personal Links.
The example below generates a distribution and then prints the results to stdout. It adds one month to the survey expiration date.
The general procedure is to:
- Generate custom link calling the Generate Distribution Links API.
- Then call List Distribution Links using the Id generated above.
- Send links to customers using email, SMS, or other preferred means.
Code and Qualtrics Support
Our support team does not offer assistance or consultation on custom coding, but you can always try asking our community of dedicated users. If you’d like to know more about our custom coding services you can commission, please contact your Qualtrics Account Executive.
from time import gmtime, strftime
from datetime import date
import datetime
import sys
import os
import requests
try:
apiToken = os.environ['APIKEY']
dataCenter = os.environ['DATACENTER']
except KeyError:
print("set environment variables APIKEY and DATACENTER")
headers = {
"x-api-token": apiToken,
"Content-Type": "application/json"
}
surveyId = "SV_9soLp9xtDjAKP53"
mailingListId = "CG_79t9MpWuwPvsGP3"
today = date.today()
oneMonth = today.replace(month=today.month+1)
distribution = {}
distribution["action"] = "CreateDistribution"
distribution["surveyId"] = surveyId
distribution["mailingListId"] = mailingListId
distribution["description"] = "distribution " + today.strftime('%Y-%m-%d %H:%M:%S')
distribution["expirationDate"] = oneMonth.strftime('%Y-%m-%d %H:%M:%S')
distribution["linkType"] = "Individual"
url='https://{0}.qualtrics.com/API/v3/distributions'.format(dataCenter)
response = requests.post(url, json=distribution, headers=headers)
dist=response.json()["result"]["id"]
if dist is None:
print (response.json())
print ("error, no links created")
sys.exit(2)
print ("distribution links Id=", dist)
url='https://{0}.qualtrics.com/API/v3/distributions/{1}/links?surveyId={2}'.format(dataCenter,dist,surveyId)
response = requests.get(url, headers=headers)
print (response.json())
Results in:
'result': {
'nextPage': None,
'elements': [{
'status': 'Email not sent',
'email': 'test@qualtrics.com',
'firstName': 'Tester',
'lastName': 'Smith',
'linkExpiration': '2018-12-13T07:00:00Z',
'link': 'https://qpartnerdev.co1.qualtrics.com/SE?Q_DL=sie4vgqlalYdJsg_9soLp9xtDjAKP53_CGC_cvWOQbiTkWaiGMt',
'exceededContactFrequency': False,
'unsubscribed': False,
'contactId': 'CID_5AdW845MGf5aUpD',
'externalDataReference': ''
}]
}