@@ -1213,39 +1213,59 @@ public function get_subscriber_tags(
1213
1213
}
1214
1214
1215
1215
/**
1216
- * Gets a list of broadcasts.
1216
+ * List broadcasts.
1217
1217
*
1218
- * @see https://developers.convertkit.com/#list-broadcasts
1218
+ * @param boolean $include_total_count To include the total count of records in the response, use true.
1219
+ * @param string $after_cursor Return results after the given pagination cursor.
1220
+ * @param string $before_cursor Return results before the given pagination cursor.
1221
+ * @param integer $per_page Number of results to return.
1219
1222
*
1220
- * @return false|array<int,\stdClass>
1223
+ * @see https://developers.convertkit.com/v4.html#list-broadcasts
1224
+ *
1225
+ * @return false|mixed
1221
1226
*/
1222
- public function get_broadcasts ()
1223
- {
1224
- return $ this ->get ('broadcasts ' );
1227
+ public function get_broadcasts (
1228
+ bool $ include_total_count = false ,
1229
+ string $ after_cursor = '' ,
1230
+ string $ before_cursor = '' ,
1231
+ int $ per_page = 100
1232
+ ) {
1233
+ // Send request.
1234
+ return $ this ->get (
1235
+ endpoint: 'broadcasts ' ,
1236
+ args: $ this ->build_total_count_and_pagination_params (
1237
+ include_total_count: $ include_total_count ,
1238
+ after_cursor: $ after_cursor ,
1239
+ before_cursor: $ before_cursor ,
1240
+ per_page: $ per_page
1241
+ )
1242
+ );
1225
1243
}
1226
1244
1227
1245
/**
1228
1246
* Creates a broadcast.
1229
1247
*
1230
- * @param string $subject The broadcast email's subject.
1231
- * @param string $content The broadcast's email HTML content.
1232
- * @param string $description An internal description of this broadcast.
1233
- * @param boolean $public Specifies whether or not this is a public post.
1234
- * @param \DateTime $published_at Specifies the time that this post was published (applicable
1235
- * only to public posts).
1236
- * @param \DateTime $send_at Time that this broadcast should be sent; leave blank to create
1237
- * a draft broadcast. If set to a future time, this is the time that
1238
- * the broadcast will be scheduled to send.
1239
- * @param string $email_address Sending email address; leave blank to use your account's
1240
- * default sending email address.
1241
- * @param string $email_layout_template Name of the email template to use; leave blank to use your
1242
- * account's default email template.
1243
- * @param string $thumbnail_alt Specify the ALT attribute of the public thumbnail image
1244
- * (applicable only to public posts).
1245
- * @param string $thumbnail_url Specify the URL of the thumbnail image to accompany the broadcast
1246
- * post (applicable only to public posts).
1247
- *
1248
- * @see https://developers.convertkit.com/#create-a-broadcast
1248
+ * @param string $subject The broadcast email's subject.
1249
+ * @param string $content The broadcast's email HTML content.
1250
+ * @param string $description An internal description of this broadcast.
1251
+ * @param boolean $public Specifies whether or not this is a public post.
1252
+ * @param \DateTime $published_at Specifies the time that this post was published (applicable
1253
+ * only to public posts).
1254
+ * @param \DateTime $send_at Time that this broadcast should be sent; leave blank to create
1255
+ * a draft broadcast. If set to a future time, this is the time that
1256
+ * the broadcast will be scheduled to send.
1257
+ * @param string $email_address Sending email address; leave blank to use your account's
1258
+ * default sending email address.
1259
+ * @param string $email_template_id ID of the email template to use; leave blank to use your
1260
+ * account's default email template.
1261
+ * @param string $thumbnail_alt Specify the ALT attribute of the public thumbnail image
1262
+ * (applicable only to public posts).
1263
+ * @param string $thumbnail_url Specify the URL of the thumbnail image to accompany the broadcast
1264
+ * post (applicable only to public posts).
1265
+ * @param string $preview_text Specify the preview text of the email.
1266
+ * @param array<string,string> $subscriber_filter Filter subscriber(s) to send the email to.
1267
+ *
1268
+ * @see https://developers.convertkit.com/v4.html#create-a-broadcast
1249
1269
*
1250
1270
* @return false|object
1251
1271
*/
@@ -1257,22 +1277,28 @@ public function create_broadcast(
1257
1277
\DateTime $ published_at = null ,
1258
1278
\DateTime $ send_at = null ,
1259
1279
string $ email_address = '' ,
1260
- string $ email_layout_template = '' ,
1280
+ string $ email_template_id = '' ,
1261
1281
string $ thumbnail_alt = '' ,
1262
- string $ thumbnail_url = ''
1282
+ string $ thumbnail_url = '' ,
1283
+ string $ preview_text = '' ,
1284
+ array $ subscriber_filter = []
1263
1285
) {
1264
1286
$ options = [
1265
- 'content ' => $ content ,
1266
- 'description ' => $ description ,
1267
- 'email_address ' => $ email_address ,
1268
- 'email_layout_template ' => $ email_layout_template ,
1269
- 'public ' => $ public ,
1270
- 'published_at ' => (!is_null ($ published_at ) ? $ published_at ->format ('Y-m-d H:i:s ' ) : '' ),
1271
- 'send_at ' => (!is_null ($ send_at ) ? $ send_at ->format ('Y-m-d H:i:s ' ) : '' ),
1272
- 'subject ' => $ subject ,
1273
- 'thumbnail_alt ' => $ thumbnail_alt ,
1274
- 'thumbnail_url ' => $ thumbnail_url ,
1287
+ 'email_template_id ' => $ email_template_id ,
1288
+ 'email_address ' => $ email_address ,
1289
+ 'content ' => $ content ,
1290
+ 'description ' => $ description ,
1291
+ 'public ' => $ public ,
1292
+ 'published_at ' => (!is_null ($ published_at ) ? $ published_at ->format ('Y-m-d H:i:s ' ) : '' ),
1293
+ 'send_at ' => (!is_null ($ send_at ) ? $ send_at ->format ('Y-m-d H:i:s ' ) : '' ),
1294
+ 'thumbnail_alt ' => $ thumbnail_alt ,
1295
+ 'thumbnail_url ' => $ thumbnail_url ,
1296
+ 'preview_text ' => $ preview_text ,
1297
+ 'subject ' => $ subject ,
1275
1298
];
1299
+ if (count ($ subscriber_filter )) {
1300
+ $ options ['subscriber_filter ' ] = $ subscriber_filter ;
1301
+ }
1276
1302
1277
1303
// Iterate through options, removing blank entries.
1278
1304
foreach ($ options as $ key => $ value ) {
@@ -1287,15 +1313,18 @@ public function create_broadcast(
1287
1313
}
1288
1314
1289
1315
// Send request.
1290
- return $ this ->post ('broadcasts ' , $ options );
1316
+ return $ this ->post (
1317
+ endpoint: 'broadcasts ' ,
1318
+ args: $ options
1319
+ );
1291
1320
}
1292
1321
1293
1322
/**
1294
1323
* Retrieve a specific broadcast.
1295
1324
*
1296
1325
* @param integer $id Broadcast ID.
1297
1326
*
1298
- * @see https://developers.convertkit.com/#retrieve-a-specific -broadcast
1327
+ * @see https://developers.convertkit.com/v4.html#get-a -broadcast
1299
1328
*
1300
1329
* @return false|object
1301
1330
*/
@@ -1310,7 +1339,7 @@ public function get_broadcast(int $id)
1310
1339
*
1311
1340
* @param integer $id Broadcast ID.
1312
1341
*
1313
- * @see https://developers.convertkit.com/#retrieve-a-specific-broadcast
1342
+ * @see https://developers.convertkit.com/v4.html#get-stats
1314
1343
*
1315
1344
* @return false|object
1316
1345
*/
@@ -1322,24 +1351,26 @@ public function get_broadcast_stats(int $id)
1322
1351
/**
1323
1352
* Updates a broadcast.
1324
1353
*
1325
- * @param integer $id Broadcast ID.
1326
- * @param string $subject The broadcast email's subject.
1327
- * @param string $content The broadcast's email HTML content.
1328
- * @param string $description An internal description of this broadcast.
1329
- * @param boolean $public Specifies whether or not this is a public post.
1330
- * @param \DateTime $published_at Specifies the time that this post was published (applicable
1331
- * only to public posts).
1332
- * @param \DateTime $send_at Time that this broadcast should be sent; leave blank to create
1333
- * a draft broadcast. If set to a future time, this is the time that
1334
- * the broadcast will be scheduled to send.
1335
- * @param string $email_address Sending email address; leave blank to use your account's
1336
- * default sending email address.
1337
- * @param string $email_layout_template Name of the email template to use; leave blank to use your
1338
- * account's default email template.
1339
- * @param string $thumbnail_alt Specify the ALT attribute of the public thumbnail image
1340
- * (applicable only to public posts).
1341
- * @param string $thumbnail_url Specify the URL of the thumbnail image to accompany the broadcast
1342
- * post (applicable only to public posts).
1354
+ * @param integer $id Broadcast ID.
1355
+ * @param string $subject The broadcast email's subject.
1356
+ * @param string $content The broadcast's email HTML content.
1357
+ * @param string $description An internal description of this broadcast.
1358
+ * @param boolean $public Specifies whether or not this is a public post.
1359
+ * @param \DateTime $published_at Specifies the time that this post was published (applicable
1360
+ * only to public posts).
1361
+ * @param \DateTime $send_at Time that this broadcast should be sent; leave blank to create
1362
+ * a draft broadcast. If set to a future time, this is the time that
1363
+ * the broadcast will be scheduled to send.
1364
+ * @param string $email_address Sending email address; leave blank to use your account's
1365
+ * default sending email address.
1366
+ * @param string $email_template_id ID of the email template to use; leave blank to use your
1367
+ * account's default email template.
1368
+ * @param string $thumbnail_alt Specify the ALT attribute of the public thumbnail image
1369
+ * (applicable only to public posts).
1370
+ * @param string $thumbnail_url Specify the URL of the thumbnail image to accompany the broadcast
1371
+ * post (applicable only to public posts).
1372
+ * @param string $preview_text Specify the preview text of the email.
1373
+ * @param array<string,string> $subscriber_filter Filter subscriber(s) to send the email to.
1343
1374
*
1344
1375
* @see https://developers.convertkit.com/#create-a-broadcast
1345
1376
*
@@ -1354,22 +1385,28 @@ public function update_broadcast(
1354
1385
\DateTime $ published_at = null ,
1355
1386
\DateTime $ send_at = null ,
1356
1387
string $ email_address = '' ,
1357
- string $ email_layout_template = '' ,
1388
+ string $ email_template_id = '' ,
1358
1389
string $ thumbnail_alt = '' ,
1359
- string $ thumbnail_url = ''
1390
+ string $ thumbnail_url = '' ,
1391
+ string $ preview_text = '' ,
1392
+ array $ subscriber_filter = []
1360
1393
) {
1361
1394
$ options = [
1362
- 'content ' => $ content ,
1363
- 'description ' => $ description ,
1364
- 'email_address ' => $ email_address ,
1365
- 'email_layout_template ' => $ email_layout_template ,
1366
- 'public ' => $ public ,
1367
- 'published_at ' => (!is_null ($ published_at ) ? $ published_at ->format ('Y-m-d H:i:s ' ) : '' ),
1368
- 'send_at ' => (!is_null ($ send_at ) ? $ send_at ->format ('Y-m-d H:i:s ' ) : '' ),
1369
- 'subject ' => $ subject ,
1370
- 'thumbnail_alt ' => $ thumbnail_alt ,
1371
- 'thumbnail_url ' => $ thumbnail_url ,
1395
+ 'email_template_id ' => $ email_template_id ,
1396
+ 'email_address ' => $ email_address ,
1397
+ 'content ' => $ content ,
1398
+ 'description ' => $ description ,
1399
+ 'public ' => $ public ,
1400
+ 'published_at ' => (!is_null ($ published_at ) ? $ published_at ->format ('Y-m-d H:i:s ' ) : '' ),
1401
+ 'send_at ' => (!is_null ($ send_at ) ? $ send_at ->format ('Y-m-d H:i:s ' ) : '' ),
1402
+ 'thumbnail_alt ' => $ thumbnail_alt ,
1403
+ 'thumbnail_url ' => $ thumbnail_url ,
1404
+ 'preview_text ' => $ preview_text ,
1405
+ 'subject ' => $ subject ,
1372
1406
];
1407
+ if (count ($ subscriber_filter )) {
1408
+ $ options ['subscriber_filter ' ] = $ subscriber_filter ;
1409
+ }
1373
1410
1374
1411
// Iterate through options, removing blank entries.
1375
1412
foreach ($ options as $ key => $ value ) {
@@ -1385,8 +1422,8 @@ public function update_broadcast(
1385
1422
1386
1423
// Send request.
1387
1424
return $ this ->put (
1388
- sprintf ('broadcasts/%s ' , $ id ),
1389
- $ options
1425
+ endpoint: sprintf ('broadcasts/%s ' , $ id ),
1426
+ args: $ options
1390
1427
);
1391
1428
}
1392
1429
@@ -1397,15 +1434,47 @@ public function update_broadcast(
1397
1434
*
1398
1435
* @since 1.0.0
1399
1436
*
1400
- * @see https://developers.convertkit.com/#destroy-webhook
1437
+ * @see https://developers.convertkit.com/v4.html#delete-a-broadcast
1401
1438
*
1402
1439
* @return false|object
1403
1440
*/
1404
- public function destroy_broadcast (int $ id )
1441
+ public function delete_broadcast (int $ id )
1405
1442
{
1406
1443
return $ this ->delete (sprintf ('broadcasts/%s ' , $ id ));
1407
1444
}
1408
1445
1446
+ /**
1447
+ * List webhooks.
1448
+ *
1449
+ * @param boolean $include_total_count To include the total count of records in the response, use true.
1450
+ * @param string $after_cursor Return results after the given pagination cursor.
1451
+ * @param string $before_cursor Return results before the given pagination cursor.
1452
+ * @param integer $per_page Number of results to return.
1453
+ *
1454
+ * @since 2.0.0
1455
+ *
1456
+ * @see https://developers.convertkit.com/v4.html#list-webhooks
1457
+ *
1458
+ * @return false|mixed
1459
+ */
1460
+ public function get_webhooks (
1461
+ bool $ include_total_count = false ,
1462
+ string $ after_cursor = '' ,
1463
+ string $ before_cursor = '' ,
1464
+ int $ per_page = 100
1465
+ ) {
1466
+ // Send request.
1467
+ return $ this ->get (
1468
+ endpoint: 'webhooks ' ,
1469
+ args: $ this ->build_total_count_and_pagination_params (
1470
+ include_total_count: $ include_total_count ,
1471
+ after_cursor: $ after_cursor ,
1472
+ before_cursor: $ before_cursor ,
1473
+ per_page: $ per_page
1474
+ )
1475
+ );
1476
+ }
1477
+
1409
1478
/**
1410
1479
* Creates a webhook that will be called based on the chosen event types.
1411
1480
*
@@ -1415,7 +1484,7 @@ public function destroy_broadcast(int $id)
1415
1484
*
1416
1485
* @since 1.0.0
1417
1486
*
1418
- * @see https://developers.convertkit.com/#create-a-webhook
1487
+ * @see https://developers.convertkit.com/v4.html #create-a-webhook
1419
1488
*
1420
1489
* @throws \InvalidArgumentException If the event is not supported.
1421
1490
*
@@ -1427,6 +1496,8 @@ public function create_webhook(string $url, string $event, string $parameter = '
1427
1496
switch ($ event ) {
1428
1497
case 'subscriber.subscriber_activate ' :
1429
1498
case 'subscriber.subscriber_unsubscribe ' :
1499
+ case 'subscriber.subscriber_bounce ' :
1500
+ case 'subscriber.subscriber_complain ' :
1430
1501
case 'purchase.purchase_create ' :
1431
1502
$ eventData = ['name ' => $ event ];
1432
1503
break ;
@@ -1474,7 +1545,7 @@ public function create_webhook(string $url, string $event, string $parameter = '
1474
1545
1475
1546
// Send request.
1476
1547
return $ this ->post (
1477
- 'automations/hooks ' ,
1548
+ 'webhooks ' ,
1478
1549
[
1479
1550
'target_url ' => $ url ,
1480
1551
'event ' => $ eventData ,
@@ -1485,17 +1556,17 @@ public function create_webhook(string $url, string $event, string $parameter = '
1485
1556
/**
1486
1557
* Deletes an existing webhook.
1487
1558
*
1488
- * @param integer $rule_id Rule ID.
1559
+ * @param integer $id Webhook ID.
1489
1560
*
1490
1561
* @since 1.0.0
1491
1562
*
1492
- * @see https://developers.convertkit.com/#destroy -webhook
1563
+ * @see https://developers.convertkit.com/v4.html#delete-a -webhook
1493
1564
*
1494
1565
* @return false|object
1495
1566
*/
1496
- public function destroy_webhook (int $ rule_id )
1567
+ public function delete_webhook (int $ id )
1497
1568
{
1498
- return $ this ->delete (sprintf ('automations/hooks/ %s ' , $ rule_id ));
1569
+ return $ this ->delete (sprintf ('webhooks/ %s ' , $ id ));
1499
1570
}
1500
1571
1501
1572
/**
0 commit comments