-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTaricCode.php
More file actions
41 lines (33 loc) · 1.06 KB
/
TaricCode.php
File metadata and controls
41 lines (33 loc) · 1.06 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
<?php declare(strict_types=1);
use MpApiClient\Common\Authenticators\ClientIdAuthenticator;
use MpApiClient\Exception\MpApiException;
use MpApiClient\MpApiClient;
use MpApiClient\MpApiClientOptions;
require '../vendor/autoload.php';
$options = new MpApiClientOptions(
new ClientIdAuthenticator('my-client-id')
);
$client = MpApiClient::createFromOptions('my-app-name', $options);
//
// Get list of all CN (Combined Nomenclature) codes
//
try {
$taricCodeList = $client->taricCode()->list();
// Print all CN codes as json object
echo json_encode($taricCodeList, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
// Get all CN codes as array
// [
// [
// 'id' => '22030010',
// ],
// ...
// ]
var_dump($taricCodeList->jsonSerialize());
// Iterate over the returned list
foreach ($taricCodeList as $taricCode) {
echo 'CN code id: ' . $taricCode->getId() . PHP_EOL;
echo PHP_EOL;
}
} catch (MpApiException $e) {
echo 'Unexpected error occurred while loading CN code list: ' . $e->getMessage();
}