1
- # ConvertKit SDK PHP
1
+ # Kit SDK PHP
2
2
3
- The ConvertKit PHP SDK provides convinient access to the ConvertKit API from applications written in the PHP language.
3
+ The Kit PHP SDK provides convinient access to the Kit API from applications written in the PHP language.
4
4
5
5
It includes a pre-defined set of methods for interacting with the API.
6
6
@@ -10,6 +10,7 @@ It includes a pre-defined set of methods for interacting with the API.
10
10
| -------------| -------------| --------------------| --------------|
11
11
| 1.x | v3 | API Key and Secret | 7.4+ |
12
12
| 2.x | v4 | OAuth | 8.0+ |
13
+ | 2.2+ | v4 | API Key | 8.0+ |
13
14
14
15
Refer to [ this guide] ( MIGRATION.md ) for changes when upgrading to the v2 SDK.
15
16
@@ -41,9 +42,9 @@ If you use Composer, these dependencies should be handled automatically.
41
42
42
43
### 2.x (v4 API, OAuth, PHP 8.0+)
43
44
44
- First, register your OAuth application in the ` OAuth Applications ` section at https://app.convertkit .com/account_settings/advanced_settings .
45
+ First, register your OAuth application in the ` OAuth Applications ` section at https://app.kit .com/account_settings/advanced_settings .
45
46
46
- Using the supplied Client ID and secret, redirect the user to ConvertKit to grant your application access to their ConvertKit account.
47
+ Using the supplied Client ID and secret, redirect the user to Kit to grant your application access to their Kit account.
47
48
48
49
``` php
49
50
// Require the autoloader (if you're using a PHP framework, this may already be done for you).
@@ -59,7 +60,7 @@ $api = new \ConvertKit_API\ConvertKit_API(
59
60
header('Location: '.$api->get_oauth_url('<your _redirect_uri >'));
60
61
```
61
62
62
- Once the user grants your application access to their ConvertKit account, they'll be redirected to your Redirect URI with an authorization code. For example:
63
+ Once the user grants your application access to their Kit account, they'll be redirected to your Redirect URI with an authorization code. For example:
63
64
64
65
` your-redirect-uri?code=<auth_code> `
65
66
@@ -118,26 +119,40 @@ $api = new \ConvertKit_API\ConvertKit_API(
118
119
API requests may then be performed:
119
120
120
121
``` php
121
- $result = $api->add_subscriber_to_form(12345, 'joe.bloggs@convertkit .com');
122
+ $result = $api->add_subscriber_to_form(12345, 'joe.bloggs@kit .com');
122
123
```
123
124
124
125
To determine whether a new entity / relationship was created, or an existing entity / relationship updated, inspect the HTTP code of the last request:
125
126
126
127
``` php
127
- $result = $api->add_subscriber_to_form(12345, 'joe.bloggs@convertkit .com');
128
+ $result = $api->add_subscriber_to_form(12345, 'joe.bloggs@kit .com');
128
129
$code = $api->getResponseInterface()->getStatusCode(); // 200 OK if e.g. a subscriber already added to the specified form, 201 Created if the subscriber added to the specified form for the first time.
129
130
```
130
131
131
132
The PSR-7 response can be fetched and further inspected, if required - for example, to check if a header exists:
132
133
133
134
``` php
134
- $result = $api->add_subscriber_to_form(12345, 'joe.bloggs@convertkit .com');
135
+ $result = $api->add_subscriber_to_form(12345, 'joe.bloggs@kit .com');
135
136
$api->getResponseInterface()->hasHeader('Content-Length'); // Check if the last API request included a `Content-Length` header
136
137
```
137
138
139
+ ### 2.2+ (v4 API, API Key, PHP 8.0+)
140
+
141
+ Get your Kit API Key and API Secret [ here] ( https://app.kit.com/account_settings/developer_settings ) and set it somewhere in your application.
142
+
143
+ ``` php
144
+ // Require the autoloader (if you're using a PHP framework, this may already be done for you).
145
+ require_once 'vendor/autoload.php';
146
+
147
+ // Initialize the API class.
148
+ $api = new \ConvertKit_API\ConvertKit_API(
149
+ apiKey: '<your _v4_api_key >'
150
+ );
151
+ ```
152
+
138
153
### 1.x (v3 API, API Key and Secret, PHP 7.4+)
139
154
140
- Get your ConvertKit API Key and API Secret [ here] ( https://app.convertkit .com/account/edit ) and set it somewhere in your application.
155
+ Get your Kit API Key and API Secret [ here] ( https://app.kit .com/account_settings/developer_settings ) and set it somewhere in your application.
141
156
142
157
``` php
143
158
// Require the autoloader (if you're using a PHP framework, this may already be done for you).
@@ -149,7 +164,7 @@ $api = new \ConvertKit_API\ConvertKit_API('<your_public_api_key>', '<your_secret
149
164
150
165
## Handling Errors
151
166
152
- The ConvertKit PHP SDK uses Guzzle for all HTTP API requests. Errors will be thrown as Guzzle's ` ClientException ` (for 4xx errors),
167
+ The Kit PHP SDK uses Guzzle for all HTTP API requests. Errors will be thrown as Guzzle's ` ClientException ` (for 4xx errors),
153
168
or ` ServerException ` (for 5xx errors).
154
169
155
170
``` php
@@ -190,4 +205,4 @@ See the [PHP SDK docs](./docs/classes/ConvertKit_API/ConvertKit_API.md)
190
205
191
206
See our [ contributor guide] ( CONTRIBUTING.md ) for setting up your development environment, testing and submitting a PR.
192
207
193
- For ConvertKit , refer to the [ deployment guide] ( DEPLOYMENT.md ) on how to publish a new release.
208
+ For Kit , refer to the [ deployment guide] ( DEPLOYMENT.md ) on how to publish a new release.
0 commit comments