-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathall.php
More file actions
95 lines (78 loc) · 2.73 KB
/
all.php
File metadata and controls
95 lines (78 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
use Mailtrap\Config;
use Mailtrap\DTO\Request\Contact\CreateContact;
use Mailtrap\DTO\Request\Contact\CreateContactEvent;
use Mailtrap\DTO\Request\Contact\ImportContact;
use Mailtrap\DTO\Request\Contact\UpdateContact;
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapGeneralClient;
use Mailtrap\DTO\Request\Contact\ContactExportFilter;
require __DIR__ . '/../../vendor/autoload.php';
$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
$contacts = (new MailtrapGeneralClient($config))->contacts($accountId);
/**
* Get all Contact Lists.
*
* GET https://mailtrap.io/api/accounts/{account_id}/contacts/lists
*/
try {
$response = $contacts->getAllContactLists();
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
/**
* Get a specific Contact List by ID.
*
* GET https://mailtrap.io/api/accounts/{account_id}/contacts/lists/{list_id}
*/
try {
$contactListId = 1; // Replace 1 with the actual list ID
$response = $contacts->getContactList($contactListId);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
/**
* Create a new Contact List.
*
* POST https://mailtrap.io/api/accounts/{account_id}/contacts/lists
*/
try {
$contactListName = 'New Contact List'; // Replace with your desired list name
$response = $contacts->createContactList($contactListName);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
/**
* Update a Contact List by ID.
*
* PATCH https://mailtrap.io/api/accounts/{account_id}/contacts/lists/{list_id}
*/
try {
$contactListId = 1; // Replace 1 with the actual list ID
$newContactListName = 'Updated Contact List Name'; // Replace with your desired list name
$response = $contacts->updateContactList($contactListId, $newContactListName);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
/**
* Delete a Contact List by ID.
*
* DELETE https://mailtrap.io/api/accounts/{account_id}/contacts/lists/{list_id}
*/
try {
$contactListId = 1; // Replace 1 with the actual list ID
$response = $contacts->deleteContactList($contactListId);
// Print the response status code
var_dump($response->getStatusCode());
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}