-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadditionalStopDetails.php
More file actions
50 lines (42 loc) · 1.17 KB
/
additionalStopDetails.php
File metadata and controls
50 lines (42 loc) · 1.17 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
<?php
// autoload all composer dependencies
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
// parse env file where is api key stored
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$data = file_get_contents(__DIR__ . '/data/additionalStopDetailsOrder.json');
$data = json_decode($data, true);
$query = <<<GRAPHQL
mutation importOrder(\$data: OrderImportInput!){
importOrder(data:\$data) {
_id
order {
reference
route {
distance
time
}
}
}
}
GRAPHQL;
$client = new Client();
$response = $client->post(
'https://dev.backend.impargo.eu/',
[
RequestOptions::HEADERS => [
'Content-Type' => 'application/json',
'authorization' => $_ENV['IMPARGO_API_KEY'],
],
RequestOptions::JSON => [
'query' => $query,
'variables' => [
'data' => $data,
],
],
]
);
$jsonResult = json_decode($response->getBody()->getContents(), true);
printf("Order successfully created: \n %s \n", json_encode($jsonResult, JSON_PRETTY_PRINT));