-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
55 lines (50 loc) · 2.18 KB
/
index.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
<?php
const API_URL = "https://api.bol.com/retailer";
const API_CLIENTID = "8338f293-a8a0-4d6c-b660-7d77d76002cb";
const API_SECRET = "aMPKgg6tsz_5fvRQbNweO4ejCaSdOI_cVb698D5YwfMy1GeAvm94YGeAD1JRjmI_eGKk0s2bRXc59NECLcrKSw";
const API_USER = "sync";
function bol_bearer() {
$session = curl_init("https://login.bol.com/token?grant_type=client_credentials");
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_USERPWD, API_CLIENTID . ':' . API_SECRET);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($session);
curl_close($session);
$j = json_decode($res, true);
if (! is_array($j)) {
user_error("http_bearer: invalid res=$res");
}
if ($j["token_type"] !== "Bearer") {
user_error("http_bearer: unsupported token type=" . $j["token_type"]);
}
if ($j["scope"] !== "RETAILER") {
var_dump($j);
user_error("http_bearer: account does not have retailer role but role=" . $j["scope"]);
}
return $j["access_token"];
}
function bol_http($method, $url, $bearer, $d = []) {
$session = curl_init(API_URL . $url);
$headers = ['Accept: application/vnd.retailer.v3+json', sprintf('Authorization: Bearer %s', $bearer)];
if (count($d) > 0) {
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($d));
$headers[] = 'Content-Type: application/json';
}
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($session, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($session);
curl_close($session);
$results = json_decode($response, true);
return $results;
}
// https://api.bol.com/retailer/public/redoc/v3#operation/post-offer-export
// Not interesting? https://developers.bol.com/documentatie/ftp/content-ftps-handleiding/
$token = bol_bearer();
$res = bol_http("GET", "/orders", $token, []);
var_dump($res);