-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqb-webhook-helper.php
110 lines (88 loc) · 2.79 KB
/
qb-webhook-helper.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
102
103
104
105
106
107
108
109
110
<?php
$realm = $_POST["realm"];
$uname = $_POST["uname"];
$pword = $_POST["pword"];
$db_id = $_POST["db"];
$app_token = $_POST["apptoken"];
$thours = $_POST["thours"];
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST["record_id"]) ) {
$record_id = $_POST["record_id"];
$data_list = array();
foreach ($_POST as $key => $value) {
if (strpos($key, "qb_send_") === 0) {
$data_list[str_replace("qb_send_", "", $key)] = $value;
}
}
$data_string = http_build_query($data_list);
$url = $_POST["set_url"];
$curl = curl_init();
if ($_POST["request_method"] =="get") {
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url."?".$data_string,
CURLOPT_USERAGENT => 'API Request'
));
} elseif ($_POST["request_method"] =="post") {
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'API Request',
CURLOPT_HTTPHEADER => array(
//'Content-Type: application/xml'
),
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data_string
));
}
$resp = curl_exec($curl);
curl_close($curl);
/*======================
QuickBase API
======================================*/
// Start connection
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://".$realm.".quickbase.com/db/main?a=API_Authenticate&username=".$uname."&password=".$pword."&hours=".$thours."",
CURLOPT_USERAGENT => 'QB Ticket Request'
));
$resp1 = curl_exec($curl);
curl_close($curl);
$xml = new SimpleXMLElement($resp1);
$ticket = $xml->ticket;
$user_id = $xml->userid;
// Start connection
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://".$realm.".quickbase.com/db/".$db_id."?a=API_GetRecordInfo&rid=".$record_id."&ticket=".$ticket."&apptoken=".$app_token."",
CURLOPT_USERAGENT => 'QB Record Request'
));
$resp2 = curl_exec($curl);
curl_close($curl);
$xml = new SimpleXMLElement($resp2);
$update_id = $xml->update_id;
$field_options = array(
"raw_response" =>$resp,
);
$post_data = array(
"rid" =>$record_id,
"update_id" =>$update_id,
);
foreach ($_POST as $key => $value) {
if (strpos($key, "_fid_") === 0 || strpos($key, "_fnm_") === 0 ) {
$post_data[$key] = $field_options[$value];
}
}
$post_string = http_build_query($post_data);
$url = "https://".$realm.".quickbase.com/db/".$db_id."?a=API_EditRecord&".$post_string."&ticket=".$ticket."&apptoken=".$app_token."";
// Start connection to QuickBase
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'QB API Request'
));
$resp = curl_exec($curl);
curl_close($curl);
}