-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNinjaVanOrderTrackingBulk.php
More file actions
68 lines (48 loc) · 1.94 KB
/
NinjaVanOrderTrackingBulk.php
File metadata and controls
68 lines (48 loc) · 1.94 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
<?php
/*
| NINJAVAN API
| Request new Token using NinjaVanAccessTokenRequest.php included
| This file make request to /2.0/track endpoint
| and return the status for the tracking id either it is pending or in transit or completed delivered
| accept parameter in array of tracking ids
| ==========================================================================================
| Reference link : https://confluence.ninjavan.co/pages/viewpage.action?pageId=819251
| ==========================================================================================
*/
$bearerToken = "";
$requestError = "";
include "NinjaVanAccessTokenRequest.php"; // to make sure token is always refreshed on each request
/*
| use endpoint_url_sandbox if you use your sandbox client_id and client_secret
| and endpoint_url if you use production client_id and client_secret
*/
$endpoint_url_production = "https://api.ninjavan.co/".$country_code."/2.0/track";
$endpoint_url_sandbox = "https://api-sandbox.ninjavan.co/".$country_code."/2.0/track";
$array_data = $_GET['tracking_id']; // via HTTP GET request
// sample_array_format = array('TR2645MY','TR7683NY','TR9862EY')
//-------------------------------------------------------------------------------------------------------------
$data['trackingIds'] = $array_data;
$fields = json_encode($data);
if($requestError != ""){
echo "Error in request : ".$requestError;
}else{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $endpoint_url_production,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $fields,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer ".$bearerToken,
"Content-Type: application/json"
)
));
$response = curl_exec($curl);
$err = curl_error($curl);
echo $response;
}
?>