forked from intacct/intacct-sdk-php-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list-vendors.php
73 lines (62 loc) · 2.48 KB
/
list-vendors.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Copyright 2018 Sage Intacct, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "LICENSE" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
require __DIR__ . '/bootstrap.php';
use Intacct\Functions\Common\Query\Comparison\EqualTo\EqualToString;
use Intacct\Functions\Common\ReadByQuery;
use Intacct\Functions\Common\ReadMore;
try {
$query = new ReadByQuery();
$query->setObjectName('VENDOR');
$query->setPageSize(2); // Keep the page size to just 2 for the example
$query->setFields([
'RECORDNO',
'VENDORID',
]);
$logger->info('Executing query to Intacct API');
$response = $client->execute($query);
$result = $response->getResult();
$logger->debug('Query successful - page 1', [
'Total count' => $result->getTotalCount(),
'Data' => json_decode(json_encode($result->getData()), 1),
]);
echo "Page 1 success! Number of vendor records found: " . $result->getTotalCount() . ". Number remaining: " . $result->getNumRemaining() . PHP_EOL;
$i = 1;
// Get pages 2 through 4
while ($result->getNumRemaining() > 0 && $i <= 3 && $result->getResultId()) {
$i++;
$more = new ReadMore();
$more->setResultId($result->getResultId());
$response = $client->execute($more);
$result = $response->getResult();
$logger->debug('Read More successful - page ' . $i, [
'Total remaining' => $result->getNumRemaining(),
'Data' => json_decode(json_encode($result->getData()), 1),
]);
echo "Page $i success! Records remaining: " . $result->getNumRemaining() . PHP_EOL;
}
echo "Successfully read $i pages" . PHP_EOL;
} catch (\Intacct\Exception\ResponseException $ex) {
$logger->error('An Intacct response exception was thrown', [
get_class($ex) => $ex->getMessage(),
'Errors' => $ex->getErrors(),
]);
echo 'Failed! ' . $ex->getMessage();
} catch (\Exception $ex) {
$logger->error('An exception was thrown', [
get_class($ex) => $ex->getMessage(),
]);
echo get_class($ex) . ': ' . $ex->getMessage();
}