-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
67 lines (49 loc) · 1.43 KB
/
api.php
File metadata and controls
67 lines (49 loc) · 1.43 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
<?php
/*
###### AirWatch internal App size API page #######
Author: Adam Matthews (matthewsa@vmware.com)
Date: 29th October 2016
TODO (AS OF 29/10/16):
* handle REST errors
*/
$crap = 10;
function CallAPI($method, $url, $data = false)
{
//echo $method;
//echo $url;
// copy file content into a string var
$json_file = file_get_contents('env.json');
$jfo = json_decode($json_file);
$env_tenantcode = $jfo->awtenantcode;
$env_auth = $jfo->auth;
//initiate curl
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $env_auth);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
$env_tenantcode,
'content-type:application/json'
));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //insecure connection allow
$result = curl_exec($curl);
echo curl_error($curl);
curl_close($curl);
return $result;
}