Skip to content

Commit f696a39

Browse files
committed
Started API docs
1 parent fd9e0c0 commit f696a39

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

DOCUMENTATION.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# ConvertKit SDK PHP Documentation
2+
3+
This documentation details the available methods provided by the PHP SDK.
4+
5+
For each method, a link to the ConvertKit API documentation is included.
6+
7+
## Getting Started
8+
9+
Get your ConvertKit API Key and API Secret [here](https://app.convertkit.com/account/edit) and set it somewhere in your application.
10+
11+
```php
12+
// Require the autoloader (if you're using a PHP framework, this may already be done for you).
13+
require_once 'vendor/autoload.php';
14+
15+
// Initialize the API class.
16+
$api = new \ConvertKit_API\ConvertKit_API('<your_public_api_key>', '<your_secret_api_key>');
17+
```
18+
19+
## Handling Errors
20+
21+
The ConvertKit PHP SDK uses Guzzle for all HTTP API requests. Errors will be thrown as Guzzle's `ClientException` (for 4xx errors),
22+
or `ServerException` (for 5xx errors).
23+
24+
```php
25+
try {
26+
$forms = $api->add_subscriber_to_form('invalid-form-id');
27+
} catch (GuzzleHttp\Exception\ClientException $e) {
28+
// Handle 4xx client errors.
29+
die($e->getMessage());
30+
} catch (GuzzleHttp\Exception\ServerException $e) {
31+
// Handle 5xx server errors.
32+
die($e->getMessage());
33+
}
34+
```
35+
36+
For a more detailed error message, it's possible to fetch the API's response when a `ClientException` is thrown:
37+
38+
```php
39+
// Errors will be thrown as Guzzle's ClientException or ServerException.
40+
try {
41+
$forms = $api->form_subscribe('invalid-form-id');
42+
} catch (GuzzleHttp\Exception\ClientException $e) {
43+
// Handle 4xx client errors.
44+
// For ClientException, it's possible to inspect the API's JSON response
45+
// to output an error or handle it accordingly.
46+
$error = json_decode($e->getResponse()->getBody()->getContents());
47+
die($error->message); // e.g. "Entity not found".
48+
} catch (GuzzleHttp\Exception\ServerException $e) {
49+
// Handle 5xx server errors.
50+
die($e->getMessage());
51+
}
52+
```
53+
54+
## Account
55+
56+
### Show the current account
57+
58+
[API Docs](https://developers.convertkit.com/#account)
59+
60+
```php
61+
$account = $api->get_account();
62+
```
63+
64+
## Forms
65+
66+
### List forms
67+
68+
[API Docs](https://developers.convertkit.com/#forms)
69+
70+
```php
71+
$forms = $api->get_forms();
72+
```
73+
74+
### List landing pages
75+
76+
[API Docs](https://developers.convertkit.com/#forms)
77+
78+
```php
79+
$landingPages = $api->get_landing_pages();
80+
```
81+
82+
### Add subscriber to a form
83+
84+
[API Docs](https://developers.convertkit.com/#add-subscriber-to-a-form)
85+
86+
```php
87+
$subscriber = $api->add_subscriber_to_form( $form_id, ... );
88+
```
89+
90+
### List subscriptions to a form
91+
92+
```php
93+
$subscriptions = $api->get_form_subscriptions(
94+
int $form_id,
95+
string $sort_order = 'asc',
96+
string $subscriber_state = 'active',
97+
int $page = 1
98+
);
99+
```
100+
101+
## Sequences
102+
103+
### List sequences
104+
105+
```php
106+
$sequences = $api->get_sequences();
107+
```
108+
109+
### Add subscriber to a sequence
110+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ $api = new \ConvertKit_API\ConvertKit_API($api_key, $api_secret);
4242

4343
## Documentation
4444

45-
See the [PHP SDK docs]()
45+
See the [PHP SDK docs](DOCUMENTATION.md)

0 commit comments

Comments
 (0)