Skip to content

Commit a4da131

Browse files
committed
get_subscriber_id method now leverages email_address field to search by email address
1 parent f1aeb0b commit a4da131

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

src/ConvertKit_API.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public function get_subscriber_id($email_address)
358358

359359
$options = array(
360360
'api_secret' => $this->api_secret,
361-
'status' => 'all',
361+
'email_address' => $email_address,
362362
);
363363

364364
$this->create_log(sprintf("GET subscriber id from all subscribers: %s, %s, %s", $request, json_encode($options),
@@ -377,30 +377,7 @@ public function get_subscriber_id($email_address)
377377
return $subscriber_id;
378378
}
379379

380-
$total_pages = $subscribers->total_pages;
381-
382-
$this->create_log(sprintf("Total number of pages is %s", $total_pages));
383-
384-
for ($i = 2; $i <= $total_pages; $i++) {
385-
$options['page'] = $i;
386-
$this->create_log(sprintf("Go to page %s", $i));
387-
$subscribers = $this->make_request($request, 'GET', $options);
388-
389-
if (!$subscribers) {
390-
return false;
391-
}
392-
393-
$subscriber_id = $this::check_if_subscriber_in_array($email_address, $subscribers->subscribers);
394-
395-
if ($subscriber_id) {
396-
return $subscriber_id;
397-
}
398-
}
399-
400-
$this->create_log("Subscriber not found anywhere");
401-
402380
return false;
403-
404381
}
405382

406383
/**
@@ -429,6 +406,30 @@ public function get_subscriber($subscriber_id)
429406

430407
}
431408

409+
/**
410+
* Update subscriber by id
411+
*
412+
* @param $subscriber_id int
413+
*
414+
* @return false|int
415+
*/
416+
public function update_subscriber($subscriber_id, array $options)
417+
{
418+
419+
if (!is_int($subscriber_id) || $subscriber_id < 1) {
420+
throw new \InvalidArgumentException;
421+
}
422+
423+
$request = $this->api_version . sprintf('/subscribers/%s', $subscriber_id);
424+
425+
$options['api_secret'] = $this->api_secret;
426+
427+
$this->create_log(sprintf("PUT subscriber: %s, %s, %s", $request, json_encode($options), $subscriber_id));
428+
429+
return $this->make_request($request, 'PUT', $options);
430+
431+
}
432+
432433
/**
433434
* Get a list of the tags for a subscriber.
434435
*

0 commit comments

Comments
 (0)