The DataService
object includes methods that are useful for getting error information. For instructions on creating a DataService
object, see Data Services APIs.
If throwExceptionOnError()
is not turned on, then for all unsuccessful requests DataService
will store the $error
object.
To retrieve the error
object, call the getLastError()
method of the DataService
object:
1 2 3 4 5 | <?php // Make the API call $result = $dataService->Add($theTargetObj); $error = $dataService->getLastError(); ?> |
By default, $dataService->getLastError()
returns FALSE
for a successful API call, so you can simply use an if
statement to check if the last API request was successful:
1 2 3 4 5 6 7 8 9 10 | <?php // Make the API call $result = $dataService->Add($theTargetObj); $error = $dataService->getLastError(); if($error) { ... } else { .... } ?> |
If the API request fails, use getHttpStatusCode()
and getResponseBody()
to get the status code and response message of the failed request, which provides information to help you identify the cause:
1 2 3 4 5 6 7 8 9 10 11 | <?php //Make the API call $result = $dataService->Add($theTargetObj); $error = $dataService->getLastError(); if($error) { echo "The Status code is: " . $error->getHttpStatusCode() . "\n"; echo "The Response message is: " . $error->getResponseBody() . "\n"; } else { .... } ?> |
Sometimes the error returned by QuickBooks Online may not be clear, and you would like Intuit Support to help identify the cause. If so, use the following code to record the Intuit-tid
from the response, and send us this value along with the Request and Response log you recorded, so we can help
you diagnose the issue:
1 2 3 | <?php $intuit_tid = $error->getIntuitTid(); ?> |