convertkit / convertkitsdk-php Goto Github PK
View Code? Open in Web Editor NEWConvertKit's official PHP SDK
ConvertKit's official PHP SDK
The exact number of pages seems to vary, but calling this function is very slow and eventually causes the API to throw a 429 error for an account with lots of subscribers, because it queries the API for all subscribers and searches the results instead of searching the API directly for the provided email.
It is possible to search by email when listing subscribers using the email_address
parameter according to https://developers.convertkit.com/#list-subscribers
Adding the email_address
parameter to $options
in get_subscriber_id()
should fix this issue.
CK API supports creating multiple tags in one go.
See API: https://developers.convertkit.com/#create-field (note the Multiple custom fields example).
The \ConvertKit_API\ConvertKit_API::create_custom_field()
method does not support this behavior allowing only a single tag per request to be created.
Modify \ConvertKit_API\ConvertKit_API::create_custom_field()
to support not just the string parameter as a single field label, but also accepting an array OR always accepting an array (even with a single field label).
I had to implement a copy of this method that basically does this:
$options = [ 'api_secret' => $this->api_secret ];
foreach ( $field_labels as $label ) {
$options['label'][] = [ 'name' => $label ];
}
return $this->post( 'custom_fields', $options );
No response
When the debugging needs to be enabled on a live site (don't ask, clients' sites), the API key is logged into a publicly available file.
That's because reconfiguring the whole site to make that log file outside of the server access is not possible - so the log file public.
So scrappers etc can accidentally see the API key.
Example of the record:
[2023-07-16T19:58:19.753138+00:00] ck-debug.INFO: GET, Request body: {"api_key":"abc1234567890def"} [] []
In order to more or less easily modify the behavior without rewriting the implementation, I'd like to be able to parse the message that is sent - and prevent the API key leaking into the log.
The easiest solution - overload the ConvertKit_API::create_log()
method in a parent class that extends the default ConvertKit_API
. After that - do the easy search-replace to remove the API key.
Right now it's impossible because that method is private
.
Can you please make it protected
?
No response
No response
Hey there,
Been struggling with the API queries taking most often 22 seconds to respond. I thought the API itself was to blame, but turned out that calling the API with cURL from bash was super fast.
Figured out the culprit:
/**
* Querying the ConvertKit API from curl like so is super fast:
* curl https://api.convertkit.com/v3/subscribers?api_secret=APIKEY&[email protected]
*
* BUT, calling it with the official ConvertKit PHP SDK is super slow, with
* speeds of 22 seconds.
*
* Here are some comparisons.
* Run these routes one at a time.
*/
// Official ConvertKit PHP SDK.
// SUPER SLOW. Often takes 22 seconds.
$app->get('/tests/convertkit/sdk/', function ($request, $response, $args) {
$api = new \ConvertKit_API\ConvertKit_API(
getenv('CONVERTKIT_API_KEY'),
getenv('CONVERTKIT_API_SECRET'),
);
$subscriber_id = $api->get_subscriber_id( '[email protected]' ); // 937488134
$response->getBody()->write(strval($subscriber_id));
return $response;
});
// Basic file_get_contents.
// SUPER SLOW. Often takes 22 seconds.
$app->get('/tests/convertkit/file_get_contents/basic/', function ($request, $response, $args) {
$url = "https://api.convertkit.com/v3/subscribers?api_secret="
. getenv('CONVERTKIT_API_SECRET')
. "&[email protected]";
$result = file_get_contents($url);
var_dump(json_decode($result, true));
return $response;
});
// file_get_contents with context trick.
// See https://stackoverflow.com/a/4240241/1717535
// Fast. Under a second.
$app->get('/tests/convertkit/file_get_contents/context/', function ($request, $response, $args) {
$url = "https://api.convertkit.com/v3/subscribers?api_secret="
. getenv('CONVERTKIT_API_SECRET')
. "&[email protected]";
$context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
$result = file_get_contents($url, false, $context);
var_dump(json_decode($result, true));
return $response;
});
// with curl
// Fast. Under a second.
$app->get('/tests/convertkit/curl/', function ($request, $response, $args) {
$url = "https://api.convertkit.com/v3/subscribers?api_secret="
. getenv('CONVERTKIT_API_SECRET')
. "&[email protected]";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result, true));
return $response;
});
This is on PHP 7.4.4 and 7.4.8. (The examples use Slim Framework.)
You should be able to confirm this for yourself.
I wasted so much time with this… (Support was very slow to respond.)
For me, this makes the PHP SDK unusable. These are also serious concerns:
Please note that since ConvertKitSDK-PHP is not yet versioned, your project will always download the latest files from master every time you run composer install which may subject you to breaking changes in the future. – from the docs
Package jeremeamia/superclosure is abandoned, you should avoid using it. Use opis/closure instead. – Composer warning
I'm a paid customer, but wary of using ConvertKit because of this.
Main class is named ConvertKit_API while the filename is ConvertKitAPI (without "_"), therefore the psr-4 loader doesn't work.
Hi, I was wondering if this package is going to be updated, the last commit was 2 years a. go, with the recent releases of php will this be upgraded?
Thanks
When I switched to using this in production, I couldn't figure out why it kept causing rate limit issues. Then I saw it works by paging through every page of subscribers, and was attempting to make over 700 API calls in a loop, for a recently added subscriber.
ConvertKitSDK-PHP/src/ConvertKit_API.php
Line 341 in e92084f
CK API supports creating multiple tags in one go.
See API: https://developers.convertkit.com/#create-a-tag (note the Multiple tags example).
The \ConvertKit_API\ConvertKit_API::create_tag()
method does not support this behavior allowing only a single tag per request to be created.
Modify \ConvertKit_API\ConvertKit_API::create_tag()
to support not just the string parameter as a single tag name, but also accepting an array OR always accepting an array (even with a single tag name).
I had to implement a copy of this method that basically does this:
$options = [ 'api_secret' => $this->api_secret ];
foreach ( $tag_labels as $label ) {
$options['tag'][] = [ 'name' => $label ];
}
return $this->post( 'tags', $options );
Hi Guys,
I'm added this repo to Packagist. Follow instructions and contact the Packagist to owned like as mantainers:
This package is not auto-updated. Please set up the GitHub Hook for Packagist so that it gets updated whenever you push!
There is no license information available for the latest version (dev-master) of this package.
Trying to install through composer and I'm getting this:
Conclusion: remove monolog/monolog 2.0.2
- Conclusion: don't install monolog/monolog 2.0.2
- convertkit/convertkitapi dev-master requires monolog/monolog ^1.0
The command:
composer require convertkit/convertkitapi:dev-master
Problem 1
- Root composer.json requires convertkit/convertkitapi dev-master -> satisfiable by convertkit/convertkitapi[dev-master].
- convertkit/convertkitapi dev-master requires guzzlehttp/guzzle ^6.3 -> found guzzlehttp/guzzle[6.3.0, ..., 6.5.x-dev] but it conflicts with your root composer.json require (^7.0.1).
My guzzle version from composer.json:
"guzzlehttp/guzzle": "^7.0.1",
Can you convert the make_request method from private to public? This will allow users to make requests to API endpoints whose methods are not implemented in the library?
For Example:
I want to get a list of all tags by calling v3/tags but there is no such method. How could I do that?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.