Friday, April 5, 2019

PHP Toolkit 2012.2: Best practice how to dump entire SOAP response via var_dump php function

Function var_dump generates full output of response given by NetSuite Web Services.
This works for any type of response, even when error is returned by NetSuite Web Services.
The var_dump function is built-in php function which means nothing needs to be installed into PHP on customer's computer.

The following example is based on sample code from SuiteAnswer article: Sample Code to Perform Search using Custom Field as Filter (25066)

Sample input - the last line of mentioned SuiteArticle ($searchResponse includes SOAP response):

$searchResponse = $service->search($request);echo '<pre>';var_dump($searchResponse);echo '</pre>';

Sample output:

object(SearchResponse)#12 (1) {  ["searchResult"]=>  object(SearchResult)#13 (8) {    ["status"]=>    object(Status)#14 (2) {      ["statusDetail"]=>      NULL      ["isSuccess"]=>      bool(true)    }    ["totalRecords"]=>    int(0)    ["pageSize"]=>    NULL    ["totalPages"]=>    int(0)    ["pageIndex"]=>    NULL    ["searchId"]=>    string(60) "WEBSERVICES_AAAAAA000000_082720131063626889609715071_6e3814f"    ["recordList"]=>    object(RecordList)#15 (1) {      ["record"]=>      NULL    }    ["searchRowList"]=>    NULL  }}

The output given by var_dump function helps debugging response returned by NetSuite. It can be used when searching how to access particular value returned by NetSuite.
Example - need to know status wheter the request was successfully processed:

$searchResponse->searchResult->status->isSuccess

No comments:

Post a Comment