-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapi.php
101 lines (81 loc) · 2.22 KB
/
webapi.php
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
96
97
98
99
100
101
<?php
include 'createidentity.php';
$url = 'http://sendgrid.com/';
$user = 'username';
$pass = 'password';
$name = 'new name';
$identity = addIdentity();
$params = array('add'=> array(
'api_user' => $user,
'api_key' => $pass,
'identity' => $identity,
'name' => $name,
'subject' => 'subject',
'html' => 'testing body',
'text' => 'testing body',
),
'list' => array(
'api_user' => $user,
'api_key' => $pass,
'name' => $name,
'list' => 'SendGrid',
),
'schedule' => array(
'api_user' => $user,
'api_key' => $pass,
'name' => $name,
'after' => 2
)
);
function addNewsletter(){
global $params;
global $url;
$request = $url.'api/newsletter/add.json';
$var = $params['add'];
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $var);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
print_r($response);
}
function addList(){
global $params;
global $url;
$request = $url.'api/newsletter/recipients/add.json';
$var = $params['list'];
// Generate curl request
$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $var);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
print_r($response);
}
function addSchedule(){
global $params;
global $url;
$request = $url.'api/newsletter/schedule/add.json';
$var = $params['schedule'];
$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $var);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
print_r($response);
}
addNewsletter();
addList();
addSchedule();