-
Notifications
You must be signed in to change notification settings - Fork 0
/
sat_api_calls.php
52 lines (41 loc) · 1.19 KB
/
sat_api_calls.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
<?php
// API endpoint URL
$url = "https://api.sat.tausi.africa/v1/mpesa/upload_pdf";
// Authorization header
$headers = array(
"Authorization: Bearer your_token"
);
// File data
$file_path = 'Miamala_2024_04_04.pdf';
$file_mime_type = mime_content_type($file_path);
$file = new CURLFile($file_path, $file_mime_type, basename($file_path));
// Other form data
$data = array(
"fullname" => "davis"
);
// Initialize cURL session
$ch = curl_init();
// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'file' => $file,
'fullname' => $data["fullname"] // Add fullname field directly to POSTFIELDS
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the cURL request
$response = curl_exec($ch);
// Check if request was successful
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 200) {
// Parse JSON response
$output_data = json_decode($response, true);
// Print output
echo json_encode($output_data, JSON_PRETTY_PRINT);
} else {
echo "Error occurred: " . $response;
}
// Close cURL session
curl_close($ch);
?>