/
distributions.R
683 lines (626 loc) · 22.7 KB
/
distributions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
#' List all distributions associated to a survey
#'
#' @param survey_id the id of survey
#'
#' @examples
#' \dontrun{
#' list_distributions("SV_erkBAsHrvoJyeYB")
#' }
#'
#' @return A \code{tibble}.
#' @export
list_distributions <- function(survey_id) {
.build_distribution <- function(list) {
df <- map_df(
list, function(x) {
tibble(
"id" = .replace_na(x$id),
"parentDistributionId" = .replace_na(x$parentDistributionId),
"ownerId" = .replace_na(x$ownerId),
"organizationId" = .replace_na(x$organizationId),
"requestStatus" = .replace_na(x$requestStatus),
"requestType" = .replace_na(x$requestType),
"createdDate" = .replace_na(x$createdDate),
"modifiedDate" = .replace_na(x$modifiedDate),
"fromEmail" = .replace_na(x$headers$fromEmail),
"replyToEmail" = .replace_na(x$headers$replyToEmail),
"fromName" = .replace_na(x$headers$fromName),
"mailingListId" = .replace_na(x$recipients$mailingListId),
"contactId" = .replace_na(x$recipients$contactId),
"libraryId" = .replace_na(x$recipients$libraryId),
"surveyId" = .replace_na(x$surveyLink$surveyId),
"sampleId" = .replace_na(x$surveyLink$sampleId),
"expirationDate" = .replace_na(x$surveyLink$expirationDate),
"linkType" = .replace_na(x$surveyLink$linkType),
"sent" = .replace_na(x$stats$sent),
"failed" = .replace_na(x$stats$failed),
"started" = .replace_na(x$stats$started),
"bounced" = .replace_na(x$stats$bounced),
"opened" = .replace_na(x$stats$opened),
"skipped" = .replace_na(x$stats$skipped),
"finished" = .replace_na(x$stats$finished),
"complaints" = .replace_na(x$stats$complaints),
"blocked" = .replace_na(x$stats$blocked)
)
})}
offset <- 0
getcnt <- .qualtrics_get("distributions", "surveyId" = survey_id, "offset" = offset)
if (length(getcnt$result)>0) {
df <- .build_distribution(getcnt$result$elements)
while (!is.null(getcnt$result$nextPage)) {
offset <- parse_url(getcnt$result$nextPage)$query$offset
getcnt <- .qualtrics_get("distributions", "surveyId" = survey_id, "offset" = offset)
df <- bind_rows(df, .build_distribution(getcnt$result$elements))
}
return(df)
} else {
return(NULL)
}
}
#' Retrieve a given survey distribution object
#'
#' @param distribution_id the distribution id
#' @param survey_id the id of the associated survey
#'
#' @return A \code{list}.
#'
#' @export
get_distribution <- function(distribution_id, survey_id) {
.build_distribution <- function(list) {
df <- map_df(
list, function(x) {
tibble(
"id" = .replace_na(x$id),
"parentDistributionId" = .replace_na(x$parentDistributionId),
"ownerId" = .replace_na(x$ownerId),
"organizationId" = .replace_na(x$organizationId),
"requestStatus" = .replace_na(x$requestStatus),
"requestType" = .replace_na(x$requestType),
"sendDate" = .replace_na(x$sendDate),
"createdDate" = .replace_na(x$createdDate),
"modifiedDate" = .replace_na(x$modifiedDate),
"headers.fromEmail" = .replace_na(x$headers$fromEmail),
"headers.replyToEmail" = .replace_na(x$headers$replyToEmail),
"headers.fromName" = .replace_na(x$headers$fromName),
"headers.subject" = .replace_na(x$headers$subject),
"recipients.mailingListId" = .replace_na(x$recipients$mailingListId),
"recipients.contactId" = .replace_na(x$recipients$contactId),
"recipients.libraryId" = .replace_na(x$recipients$libraryId),
"recipients.sampleId" = .replace_na(x$recipients$sampleId),
"message.libraryId" = .replace_na(x$message$libraryId),
"message.messageId" = .replace_na(x$message$messageId),
"message.messageText" = .replace_na(x$message$messageText),
"surveyLink.surveyId" = .replace_na(x$surveyLink$surveyId),
"surveyLink.expirationDate" = .replace_na(x$surveyLink$expirationDate),
"surveyLink.linkType" = .replace_na(x$surveyLink$linkType),
"stats.sent" = .replace_na(x$stats$sent),
"stats.failed" = .replace_na(x$stats$failed),
"stats.started" = .replace_na(x$stats$started),
"stats.bounced" = .replace_na(x$stats$bounced),
"stats.opened" = .replace_na(x$stats$opened),
"stats.skipped" = .replace_na(x$stats$skipped),
"stats.finished" = .replace_na(x$stats$finished),
"stats.complaints" = .replace_na(x$stats$complaints),
"stats.blocked" = .replace_na(x$stats$blocked)
)})
}
offset <- 0
params <- c("distributions", distribution_id)
getcnt <- .qualtrics_get(params, "surveyId"=survey_id)
if (length(getcnt$result$elements)>0) {
df <- .build_distribution(getcnt$result$elements)
while (!is.null(getcnt$result$nextPage)) {
offset <- parse_url(getcnt$result$nextPage)$query$offset
getcnt <- .qualtrics_get(params, "surveyId"=survey_id)
df <- rbind(df,.build_distribution(getcnt$result$elements))
}
return(df)
} else {
return(NULL)
}
}
#' Delete a survey distribution
#'
#' @param distribution_id the distribution id
#' @examples
#' \dontrun{delete_distribution("EMD_012345678901234")}
#' @return A status execution code
#' @export
delete_distribution <- function(distribution_id) {
params <- c("distributions", distribution_id)
getcnt <- .qualtrics_delete(params, NULL, NULL)
getcnt$meta$httpStatus
}
#' Create an email distribution or generate distribution links
#'
#' @description
#' Using this API call, you can either schedule an email distribution
#' using the Qualtrics email server, or generate distribution links
#' that you can then use to share the link to your survey using your own
#' email solution.
#'
#' @param survey_id the survey id
#' @param library_id the library id where the message is saved (see 'list_libraries')
#' @param message_id id of the message item
#' @param from_email sender email, default is \email{noreply@@qualtrics.com}
#' @param from_name appearing sender name, default is Qualtrics
#' @param subject email subject, default is "Survey Distribution"
#' @param send_date date for distribution to be sent (if not supplied will be set to +1 day)
#' @param mailing_list_id optional, mailing list is, or set transaction_batch_id
#' @param transaction_batch_id optional, transaction batch, or set mailing_list_id
#' @param contact_id optional, optional contact lookup ID for individual distribution
#' @param reply_to_email optional, reply email, default is \email{noreply@@qualtrics.com}
#' @param type optional, allowed values: Individual, Multiple, Anonymous
#' @param expiration_date expiration date
#'
#' @details
#' In order to create a new email distribution using the API, you need
#' to have the body of your email already created as a message in your
#' Qualtrics message library (see 'list_messages'). If you want to send the
#' distribution to only one contact in the mailing list, specific the contact_id
#' field in addition to the mailing_list_id (see 'list_contacts').
#'
#' @details
#' Note that your Qualtrics account may be set with a different time zone than your
#' local environment. Make sure to specificy your date fields accordingly.
#'
#' @examples
#' \dontrun{
#' create_email_distribution(
#' "SV_erkBAsHrvoJyeYB",
#' "UR_0NXtl92JJWqfWcJ",
#' "MS_0fddN2xI3J0nGQZ",
#' "ML_7aoriSKinHh8MfP",
#' "john.doe@qualtrics.com",
#' "John Doe",
#' "Participate in this awesome survey")
#' }
#' @return The created distribution id
#' @export
create_email_distribution <- function(
survey_id,
library_id,
message_id,
mailing_list_id,
from_email = "noreply@qualtrics.com",
from_name = "Qualtrics",
subject = "Participate in this survey",
send_date = paste0(Sys.Date()+2, "T00:00:00Z"),
transaction_batch_id = NULL,
contact_id = NULL,
reply_to_email = "noreply@qualtrics.com",
type = NULL,
expiration_date = NULL
) {
body_message <- list(
"libraryId" = library_id,
"messageId" = message_id
) %>%
discard(is.null)
body_header <- list(
"fromEmail" = from_email,
"fromName" = from_name,
"replyToEmail" = reply_to_email,
"subject" = subject
) %>%
discard(is.null)
body_recipients <- list(
"contactId" = contact_id,
"mailingListId" = mailing_list_id,
"transactionBatchId" = transaction_batch_id
) %>%
discard(is.null)
body_survey_link <- list(
"surveyId" = survey_id,
"expirationDate" = expiration_date,
"type" = type
) %>%
discard(is.null)
body <- list(
"message" = body_message,
"recipients" = body_recipients,
"header" = body_header,
"surveyLink" = body_survey_link,
"sendDate"= send_date
)
getcnt <- .qualtrics_post("distributions", NULL, body)
getcnt$result$id
}
#' Create a reminder distribution for an existing email distribution
#'
#' @description
#' Based on an existing email distribution, create a reminder to
#' take a survey for recipients with non completed surveys.
#' Recipients who have opted out will not receive the reminder.
#'
#' @param parent_distribution_id id of the library item
#' @param library_id Library ID of the message
#' @param message_id id of the message item
#' @param subject email subject, default is "Reminder - Participate to the survey"
#' @param send_date date for distribution to be sent (default to time + 1 day)
#' @param from_email sender email, default is \email{noreply@@qualtrics.com}
#' @param from_name appearing sender name, default is Qualtrics
#' @param reply_to_email reply email, default is \email{noreply@@qualtrics.com}
#'
#' @details
#' The parent distribution id can be found using the
#' 'list_distributions' call. The sender email parameter
#' can only be sent from another email if
#' the organization authorizes a send on its behalf.
#'
#' @examples
#' \dontrun{
#' create_reminder_distribution(
#' "EMD_6yYmF6vopfUz4gn",
#' library_id = "UR_0NXtl92JJWqfWcJ",
#' message_id = "MS_0fddN2xI3J0nGQZ"
#' )
#' }
#'
#' @return The reminder distribution id
#'
#' @export
create_reminder_distribution <- function(
parent_distribution_id,
library_id,
message_id,
subject = "Reminder - Participate to the survey",
send_date = paste0(Sys.Date()+2, "T00:00:00Z"),
from_email = "noreply@qualtrics.com",
from_name = "Qualtrics",
reply_to_email = "noreply@qualtrics.com"
) {
body <- list(
"header" = list(
"fromName" = from_name,
"replyToEmail" = reply_to_email,
"fromEmail" = from_email,
"subject" = subject
),
"message" = list(
"libraryId" = library_id,
"messageId" = message_id
),
"sendDate"= send_date
)
params <- c("distributions", parent_distribution_id, "reminders")
getcnt <- .qualtrics_post(params, NULL, body)
return(getcnt$result$distributionId)
}
#' Create a thank you distribution for an exisiting email distribution
#'
#' @description
#' The thank you email is sent to all respondents who have finished
#' the survey.
#'
#' @param parent_distribution_id id of the library item
#' @param library_id Library ID of the message
#' @param message_id id of the message item
#' @param send_date date for distribution to be sent
#' @param from_email sender email, default is \email{noreply@@qualtrics.com}
#' @param from_name appearing sender name, default is Qualtrics
#' @param reply_to_email reply email, default is \email{noreply@@qualtrics.com}
#' @param subject email subject, default is "Thank you for your participation"
#'
#' @examples
#' \dontrun{
#' create_thankyou_distribution(
#' "EMD_6yYmF6vopfUz4gn",
#' "UR_0NXtl92JJWqfWcJ",
#' "MS_0fddN2xI3J0nGQZ"
#' )
#' }
#'
#' @return The thank you distribution id
#'
#' @export
create_thankyou_distribution <- function(
parent_distribution_id,
library_id,
message_id,
send_date = paste0(Sys.Date()+2, "T00:00:00Z"),
from_email = "noreply@qualtrics.com",
from_name = "Qualtrics",
reply_to_email = "noreply@qualtrics.com",
subject = "Thank you for your participation") {
body <- list(
"header" = list(
"fromName" = from_name,
"replyToEmail" = reply_to_email,
"fromEmail" = from_email,
"subject" = subject
),
"message" = list(
"libraryId" = library_id,
"messageId" = message_id
),
"sendDate"= send_date
)
params <- c("distributions",parent_distribution_id,"thankyous")
getcnt <- .qualtrics_post(params, NULL, body)
getcnt$result$distributionId
}
#' Generate survey distribution links
#'
#' @description
#' Create a distribution without sending any emails. The created distribution
#' will be of type "GeneratedInvite". The survey must be active before you can
#' generate a distribution invite. Refer to the documentation below for further
#' information regarding usage of this API's result.
#'
#' @param survey_id the survey id
#' @param mailinglist_id the mailing list id
#' @param description name of the created ditribution (default is *Generated Links*)
#' @param linktype the link type (default is Individual. Can be Multiple or Anonymous)
#' @param action default is CreateDistribution. To generate transaction distribution links, value must be "CreateTransactionBatchDistribution"
#' @param expirationdate the id of survey
#'
#' @details
#' To retrieve the actual links, use the 'list_distribution_links' call.
#'
#' @examples
#' \dontrun{
#' generate_distribution_links(
#' "SV_erkBAsHrvoJyeYB",
#' "ML_7aoriSKinHh8MfP")
#' generate_distribution_links(
#' "SV_erkBAsHrvoJyeYB",
#' "ML_7aoriSKinHh8MfP",
#' "Survey Respondents Generated Links"
#' "Multiple"
#' }
#'
#' @return The id of the created distribution
#'
#' @export
generate_distribution_links <- function(
survey_id,
mailinglist_id,
description = "Generated Links",
linktype = "Individual",
action = "CreateDistribution",
expirationdate = NULL) {
body <- list(
"action" = action,
"surveyId" = survey_id,
"mailingListId" = mailinglist_id,
"description" = description,
"expirationDate" = expirationdate,
"linkType" = linktype
)
getcnt <- .qualtrics_post("distributions", NULL, body)
getcnt$result$id
}
#' List the survey links associated with a distribution
#'
#' @description
#' Distribution links can only be generated for distribution ids associated
#' with mailing lists. It is not possible to retrieve survey links for
#' distributions to only one contact id.
#'
#' @param survey_id the id of survey
#' @param distribution_id the distribution id
#'
#' @examples
#' \dontrun{
#' lst_distri <- list_distributions("SV_dg0P0pcZoDYvpNX")
#' df <- list_distribution_links("EMD_3rrDZa8AQBnACYl", "SV_dg0P0pcZoDYvpNX")
#' }
#'
#' @return A \code{tibble}.
#' @export
list_distribution_links <- function(distribution_id, survey_id) {
.build_df <- function(list) {
df <- map_df(
list, function(x) {
tibble(
"contactId" = .replace_na(x$contactId),
"link" = .replace_na(x$link),
"exceededContactFrequency" = .replace_na(x$exceededContactFrequency),
"linkExpiration" = .replace_na(x$linkExpiration),
"status" = .replace_na(x$status),
"lastName" = .replace_na(x$lastName),
"firstName" = .replace_na(x$firstName),
"externalDataReference" = .replace_na(x$externalDataReference),
"email" = .replace_na(x$email),
"unsubscribed" = .replace_na(x$unsubscribed)
)})
}
skip_token <- 0
params <- c("distributions", distribution_id, "links")
getcnt <- .qualtrics_get(params, "surveyId" = survey_id, "skipToken" = skip_token)
if (length(getcnt$result$elements)>0) {
df <- .build_df(getcnt$result$elements)
while (!is.null(getcnt$result$nextPage)) {
skip_token <- parse_url(getcnt$result$nextPage)$query$skipToken
getcnt <- .qualtrics_get(params, "surveyId" = survey_id, "skipToken" = skip_token)
df <- rbind(df, .build_df(getcnt$result$elements))
}
return(df)
} else {
return(NULL)
}
}
#' Send Email to Mailing List
#'
#' @description
#' You can use this call to send an email to a mailing list without
#' having to create the email message in Qualtrics first.
#'
#' @param mailingListId the id of survey
#' @param sendDate the date to send the email (default is +1 day)
#' @param fromEmail sender email, default is \email{noreply@@qualtrics.com}
#' @param fromName the send name default is Qualtrics
#' @param replyToEmail reply email, default is \email{noreply@@qualtrics.com}
#' @param subject the email subject
#' @param messageText email text body
#'
#' @examples
#' \dontrun{
#' create_distribution(
#' "ML_7aoriSKinHh8MfP",
#' "john.doe@qualtrics.com",
#' "John Doe",
#' "Participate in this awesome survey")
#' }
#'
#' @return The email distribution id
#' @export
send_email_mailinglist <- function(
mailingListId,
sendDate = paste0(Sys.Date()+1, "T00:00:00Z"),
subject = "Take this survey",
messageText = "Hello, take this survey",
fromEmail = "noreply@qualtrics.com",
fromName = "Qualtrics",
replyToEmail = "noreply@qualtrics.com"
) {
body <- list(
"header" = list(
"fromEmail" = fromEmail,
"fromName" = fromName,
"replyToEmail" = replyToEmail,
"subject" = subject
),
"message" = list(
"messageText" = messageText
),
"recipients" = list(
"mailingListId" = mailingListId
),
"sendDate"= sendDate
)
getcnt <- .qualtrics_post("distributions", NULL, body)
getcnt$meta$httpStatus
}
#' Create a new survey distribution via SMS
#'
#' @param send_date date for distribution to be sent
#' @param method Determines how the survey will be sent out via SMS. Can be
#' either Invite, Interactive, Reminder or Thankyou.
#' @param survey_id the id of survey to copy
#' @param name Name for the SMS distribution
#' @param message_id ID of the message. The messageId is required in conjunction
#' with the libraryId if no messageText is supplied. A message object is only
#' required with the Invite, Reminder, and Thankyou methods.
#' @param library_id Library ID of the message. libraryId is required in
#' conjunction with the messageId if no messageText is supplied. A message
#' object is only required by "Invite" method.
#' @param messagetext Custom message text. Either messageText or messageId must
#' be provided but not both. A message object is only required with the Invite,
#' Reminder, and Thankyou methods.
#' @param mailinglist_id Mailing List ID for a batch distribution - Required for
#' Invite and Interactive method. Cannot be provided for Reminder and Thankyou
#' @param contact_id Contact ID for an individual distribution. Cannot be
#' provided for Reminder and Thankyou
#' @param parentdistribution_id ID of the distribution to send a Reminder or
#' Thankyou distribution. Can be used only with these two methods.
#' @return A \code{list}
create_sms_distribution <- function(
send_date,
method,
survey_id,
name,
mailinglist_id,
message_id = NULL,
library_id = NULL,
messagetext=NULL,
contact_id = NULL,
parentdistribution_id = NULL
) {
body <- list(
"sendDate"= send_date,
"method" = method,
"surveyId" = survey_id,
"name" = name,
"recipients" = list(
"mailingListId" = mailinglist_id,
"contactId" = ifelse(!is.null(contact_id),contact_id,NULL)
),
"message" = ifelse(
method!="Interactive",
list(
"libraryId" = library_id,
"messageId" = ifelse(is.null(messagetext),message_id, NULL),
"messagetext" = ifelse(!is.null(messagetext), messagetext, NULL)
),
NULL
)
)
params <- ifelse((method=="Reminder" | method=="Thankyou") & !is.null(parentdistribution_id),
c("distributions",parentdistribution_id,"sms"),
c("distributions","sms"))
.qualtrics_post(params, NULL, body)
}
#' Retrieve an sms survey distribution object
#'
#' @param smsdistribution_id the distribution id
#' @param survey_id the distribution id
#' @examples
#' \dontrun{get_sms_distribution("SMSD_012345678901234", "SV_012345678901234")}
#' @return A \code{list}
get_sms_distribution <- function(smsdistribution_id, survey_id) {
params <- c("distributions","sms", smsdistribution_id)
.qualtrics_get(params, "surveyId"=survey_id, NULL)
}
#' Delete an sms survey distribution
#'
#' @param smsdistribution_id the distribution id
#' @examples
#' \dontrun{delete_sms_distribution("SMSD_012345678901234")}
#' @return A status execution code
delete_sms_distribution <- function(smsdistribution_id) {
params <- c("distributions","sms", smsdistribution_id)
getcnt <- .qualtrics_delete(params, NULL, NULL)
getcnt$meta$httpStatus
}
#' List all sms distributions associated to a survey
#'
#' @param survey_id the distribution id
#' @examples
#' \dontrun{list_sms_distributions("SV_012345678901234")}
#' @return A \code{list}
list_sms_distributions <- function(survey_id) {
.build_sms_distribution <- function(list) {
df <- map_df(
list, function(x) {
tibble(
"id" = .replace_na(x$id),
"name" = .replace_na(x$name),
"ownerId" = .replace_na(x$ownerId),
"organizationId" = .replace_na(x$organizationId),
"requestStatus" = .replace_na(x$requestStatus),
"requestType" = .replace_na(x$requestType),
"sendDate" = .replace_na(x$sendDate),
"surveyId" = .replace_na(x$surveyId),
"recipients.mailingListId" = .replace_na(x$recipients$mailingListId),
"recipients.contactId" = .replace_na(x$recipients$contactId),
"recipients.libraryId" = .replace_na(x$recipients$libraryId),
"message.libraryId" = .replace_na(x$message$libraryId),
"message.messageId" = .replace_na(x$message$messageId),
"message.messageText" = .replace_na(x$message$messageText),
"stats.sent" = .replace_na(x$stats$sent),
"stats.failed" = .replace_na(x$stats$failed),
"stats.started" = .replace_na(x$stats$started),
"stats.finished" = .replace_na(x$stats$finished),
"stats.credits" = .replace_na(x$stats$credits),
"stats.segments" = .replace_na(x$stats$segments)
)})
}
params <- c("distributions","sms")
getcnt <- .qualtrics_get(params, "surveyId"=survey_id)
return(getcnt)
offset <- 0
getcnt <- .qualtrics_get(params, "surveyId" = survey_id, "offset" = offset)
if (length(getcnt$result$elements)>0) {
df <- .build_sms_distribution(getcnt$result$elements)
while (!is.null(getcnt$result$nextPage)) {
offset <- parse_url(getcnt$result$nextPage)$query$offset
getcnt <- .qualtrics_get(params, "surveyId" = survey_id, "offset" = offset)
df <- rbind(df,.build_sms_distribution(getcnt$result$elements))
}
return(df)
} else {
return(NULL)
}
}