Skip to content

Commit 687d57d

Browse files
committed
Add add_subscribers_to_forms bulk method
1 parent 20c7bca commit 687d57d

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

src/ConvertKit_API_Traits.php

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,63 @@ public function get_landing_pages(
222222
);
223223
}
224224

225+
/**
226+
* Adds subscribers to forms in bulk.
227+
*
228+
* @param array<array<string,int>> $forms_subscribers_ids Array of arrays comprising of `form_id` and `subscriber_id`.
229+
* @param string $referrer Referrer URL.
230+
* @param string $callback_url URL to notify for large batch size when async processing complete.
231+
*
232+
* @since 2.1.0
233+
*
234+
* @see https://developers.kit.com/v4.html#bulk-add-subscribers-to-forms
235+
*
236+
* @return false|object
237+
*/
238+
public function add_subscribers_to_forms(array $forms_subscribers_ids, string $referrer = '', string $callback_url = '')
239+
{
240+
// Build parameters.
241+
$options = [
242+
'additions' => $forms_subscribers_ids,
243+
];
244+
if (!empty($referrer)) {
245+
$options['referrer'] = $referrer;
246+
}
247+
if (!empty($callback_url)) {
248+
$options['callback_url'] = $callback_url;
249+
}
250+
251+
// Send request.
252+
return $this->post(
253+
'bulk/forms/subscribers',
254+
$options
255+
);
256+
}
257+
225258
/**
226259
* Adds a subscriber to a form by email address
227260
*
228261
* @param integer $form_id Form ID.
229262
* @param string $email_address Email Address.
263+
* @param string $referrer Referrer.
230264
*
231265
* @see https://developers.convertkit.com/v4.html#add-subscriber-to-form-by-email-address
232266
*
233267
* @return false|mixed
234268
*/
235-
public function add_subscriber_to_form_by_email(int $form_id, string $email_address)
269+
public function add_subscriber_to_form_by_email(int $form_id, string $email_address, string $referrer = '')
236270
{
271+
// Build parameters.
272+
$options = ['email_address' => $email_address];
273+
274+
if (!empty($referrer)) {
275+
$options['referrer'] = $referrer;
276+
}
277+
278+
// Send request.
237279
return $this->post(
238280
sprintf('forms/%s/subscribers', $form_id),
239-
['email_address' => $email_address]
281+
$options
240282
);
241283
}
242284

@@ -245,16 +287,28 @@ public function add_subscriber_to_form_by_email(int $form_id, string $email_addr
245287
*
246288
* @param integer $form_id Form ID.
247289
* @param integer $subscriber_id Subscriber ID.
290+
* @param string $referrer Referrer URL.
248291
*
249292
* @see https://developers.convertkit.com/v4.html#add-subscriber-to-form
250293
*
251294
* @since 2.0.0
252295
*
253296
* @return false|mixed
254297
*/
255-
public function add_subscriber_to_form(int $form_id, int $subscriber_id)
298+
public function add_subscriber_to_form(int $form_id, int $subscriber_id, string $referrer = '')
256299
{
257-
return $this->post(sprintf('forms/%s/subscribers/%s', $form_id, $subscriber_id));
300+
// Build parameters.
301+
$options = [];
302+
303+
if (!empty($referrer)) {
304+
$options['referrer'] = $referrer;
305+
}
306+
307+
// Send request.
308+
return $this->post(
309+
sprintf('forms/%s/subscribers/%s', $form_id, $subscriber_id),
310+
$options
311+
);
258312
}
259313

260314
/**

0 commit comments

Comments
 (0)