-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProcerduralEx.php
More file actions
95 lines (83 loc) · 3.69 KB
/
ProcerduralEx.php
File metadata and controls
95 lines (83 loc) · 3.69 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
/*
This is an example of hitting the pardot API with extremely procedureal code
This will be a bit of a pain to write, functions ftw.
* @author stephenreid
* @desc a procedural (redundant) example of using the pardot API
* @since 7/14/2011
*
* I / Pardot make no guarantees as to the accuracy of this document.
* As you are free to use this, it also comes with no additional support.
* If you do have questions for support, please email them the actual query (url + parameters)
* that you are trying to make and why the results are not working for you
* WE WILL NOT DEBUG YOUR CODE
* WE CAN NOT MAKE ESTIMATES ON BUILDING ON THIS CODE
*
*/
//authenticate to get an api key for an hour
$userKey ='UserKeyCanBeFoundByClickingOnYourEmailAddressInTheTopRightOfPardot';
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(array('username'=>'test@pardot.com','password'=>'123abc','user_key'=>$userKey)),
)
));
$res = file_get_contents('https://pi.pardot.com/api/login/version/3',false,$context);
$res = simplexml_load_string($res);
$apiKey = $res->api_key;
//create a new prospect (upsert is often safer), for newProspect@pardot.com
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(array('user_key'=>$userKey,'api_key'=>$apiKey,'email'=>'newProspect@pardot.com')),
)
));
$res = file_get_contents('https://pi.pardot.com/api/prospect/version/3/do/create',false,$context);
//update a prospect's (newProspect@pardot.com) company to Pardot
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(array('user_key'=>$userKey,'api_key'=>$apiKey,'company'=>'Pardot')),
)
));
$res = file_get_contents('https://pi.pardot.com/api/prospect/version/3/do/update/email/newProspect@pardot.com',false,$context);
//update a prospect's custom field
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(array('user_key'=>$userKey,'api_key'=>$apiKey,'custom_field_name'=>'custom_field_value')),
)
));
$res = file_get_contents('https://pi.pardot.com/api/prospect/version/3/do/update/email/newProspect@pardot.com',false,$context);
//subscribe a prospect to a list (id= 8)
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(array('user_key'=>$userKey,'api_key'=>$apiKey,'list_8'=>'1')),
)
));
$res = file_get_contents('https://pi.pardot.com/api/prospect/version/3/do/update/email/newProspect@pardot.com',false,$context);
//now unsubscribe them from that same list
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(array('user_key'=>$userKey,'api_key'=>$apiKey,'list_8'=>'0')),
)
));
$res = file_get_contents('https://pi.pardot.com/api/prospect/version/3/do/update/email/newProspect@pardot.com',false,$context);
//query all prospects updated recently
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(array('user_key'=>$userKey,'api_key'=>$apiKey)),
)
));
$res = file_get_contents('https://pi.pardot.com/api/prospect/version/3/do/query/updated_after/yesterday',false,$context);
?>