I am trying to return all inventory from a certain warehouse in Netsuite. I am having some issues and was wondering if anyone could point me in the right direction. The internalId of the warehouse I am trying to query is 16. When I do the search it returns 0 items - but doesn't fail.
Here is the PHP code I am working with.
<?php
require_once 'PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
$internalID = '16'; //Internal ID of the warehouse I want to query to see what inventory it has
$inventorySearch = new nsComplexObject("ItemSearchBasic");
$searchValue = new nsRecordRef(array('type' => 'location', 'internalId' => $internalID ));
$multiSelect = new nsComplexObject('SearchMultiSelectField');
$multiSelect->setFields(array('operator'=>'anyOf','searchValue'=>$searchValue,"operatorSpecified" => true));
$inventorySearch->setFields(array('location'=>$multiSelect));
try
{
$searchResponse = $myNSclient->search($inventorySearch);
$totalRecords = $searchResponse->totalRecords;
if ($totalRecords > 0)
{
echo "records found";
foreach ($searchResponse->recordList as $record)
{
echo "<pre>";
print_r($record);
echo "</pre>";
}
}
else
{
echo "No result found.";
}
}
catch (Exception $e)
{
echo $e;
echo "Item is not found. Please try again.";
exit();
}
Here is the SOAP request
<?xml version="1.0" encoding="UTF-8" ?>
- <Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:core_2011_2.platform.webservices.netsuite.com" xmlns:ns2="urn:common_2011_2.platform.webservices.netsuite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="urn:messages_2011_2.platform.webservices.netsuite.com">
- <Header>
- <passport actor="http://schemas.xmlsoap.org/soap/actor/next">
<email>xxxxx</email>
<password>[Content Removed for Security Reasons]</password>
<account>xxxxxx</account>
<role internalId="3" xsi:type="RecordRef" />
</passport>
</Header>
- <Bod
y>
- <search>
- <searchRecord xsi:type="ItemSearchBasic">
- <location operator="anyOf">
<searchValue internalId="16" type="location" />
</location>
</searchRecord>
</search>
</Body>
</Envelope>
$inventorySearch = new nsComplexObject("ItemSearchBasic");
$inventorySearch->setFields(array(
"location" => array(
"operator" => "anyOf",
"searchValue" => array(
"type" => "location",
"internalId" => $internalId
)
)
));
Then, do your try/catch.
But as I look at this, you are wanting to get item availability. That's a completely different call.
$filter = new nsComplexObject ( 'ItemAvailabilityFilter' );
$filter->setFields ( array (
"location" => array (
"operator" => "anyOf",
"searchValue" => new nsRecordRef ( array (
"type" => "location",
"internalId" => $internalId
) )
)
) );
I've spent significant amount of time building my own custom search using PHPToolKit v2011.2 endpoint, and got them to work after pulling my hair out as there aren't that many examples. With introduction of v2012_2 endpoint, things have changed and I have to relearn the things that I solved before. I "strongly" suggest that you use SAVED SEARCH, instead of trying to invent the way to do all your searches in PHP. Create a saved search in Netsuite, and call the SAVED SEARCH from your PHP with internalId of the search you created.
Related
I have been struggling for hours now on a SOAP connection and can't get it to work, this is what I have:
$url = 'https://xxx/connector.svc?singleWsdl';
$user = 'user';
$pass = 'pass';
$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
try {
$soapclient = new SoapClient($url, $options);
# $soapclient = new SoapClient($url);
}
catch(Exception $e) {
die($e->getMessage());
}
I tried '?wdsl' but then I get:
PHP Fatal error: SOAP-ERROR: Parsing WSDL: <message> 'IConnector_GetProduct_ServiceFaultFault_FaultMessage' already defined
A request with no parameters works fine:
$result = $soapclient->GetVersionInfo();
$last_request = $soapclient->__getLastRequest();
$last_response = $soapclient->__getLastResponse();
print "Request: ".$last_request ."\n";
print "Response: ".$last_response."\n";
print_r($result);
Result:
Request: <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="Unit4.AgressoWholesale.Connectors"><SOAP-ENV:Body><ns1:GetVersionInfo/></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetVersionInfoResponse xmlns="Unit4.AgressoWholesale.Connectors"><GetVersionInfoResult xmlns:a="http://schemas.datacontract.org/2004/07/Unit4.AgressoWholesale.Common.Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:FullVersion>14.4.18.0</a:FullVersion><a:Release>14</a:Release><a:ServicePack>4</a:ServicePack><a:Fix>18</a:Fix><a:Version>0</a:Version><a:CustomCode/><a:AWBuild>38</a:AWBuild><a:AWFix>003</a:AWFix><a:AWCustomBuild/><a:AWCustomFix/><a:AWCustomCustomerCode/></GetVersionInfoResult></GetVersionInfoResponse></s:Body></s:Envelope>
stdClass Object
(
[GetVersionInfoResult] => stdClass Object
(
[FullVersion] => 14.4.18.0
[Release] => 14
[ServicePack] => 4
[Fix] => 18
[Version] => 0
[CustomCode] =>
[AWBuild] => 38
[AWFix] => 003
[AWCustomBuild] =>
[AWCustomFix] =>
[AWCustomCustomerCode] =>
)
)
So far so good, but the trouble begins trying to log in, which is a must.. In SoapUI it works with:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:unit="Unit4.AgressoWholesale.Connectors" xmlns:unit1="http://schemas.datacontract.org/2004/07/Unit4.AgressoWholesale.Common.Contracts">
<soapenv:Header/>
<soapenv:Body>
<unit:Login>
<unit:SecurityContext>
<unit1:SessionToken></unit1:SessionToken>
<unit1:UserId>user</unit1:UserId>
<unit1:Password>pass</unit1:Password>
</unit:SecurityContext>
</unit:Login>
</soapenv:Body>
</soapenv:Envelope>
But converting this to PHP, I'm stranding here.. this is what I have tried:
$data = array( 'SecurityContext' => array( 'SessionToken' => ''
,'Password' => $user
,'UserId' => $pass)
);
$data = array( 'SessionToken' => ''
,'Password' => $user
,'UserId' => $pass
);
$data = new stdClass;
$data->SecurityContext = new stdClass;
$data->SecurityContext->SessionToken = '';
$data->SecurityContext->UserId = $pass;
$data->SecurityContext->Password = $user;
#$result = $soapclient->__call('Login',array($data));
#$result = $soapclient->Login($data);
$result = $soapclient->__soapCall('Login',array($data));
But no matter what I try, event without parameters or an empty array or stdClass, I get:
PHP Fatal error: Uncaught SoapFault exception: [s:ServiceFault] An exception occurred
It's driving me nuts, I can't find anything on the internet about the fatal exeption '[s:ServiceFault]'
What am I doing wrong? Any help will be greatly appreciated!
OK, writing out the problem sometimes is enough to get to an anwer!
The solution was two-fold:
1) get better error reporting by using a try{} catch:
try {
$result = $soapclient->__call('Login',array($data));
#$result = $soapclient->Login($data);
#$result = $soapclient->__soapCall('Login',array($data));
} catch (SoapFault $e) {
$error = $e->faultcode;
echo str_replace('>',">\n",$error) ;
}
$last_request = $soapclient->__getLastRequest();
$last_response= $soapclient->__getLastResponse();
print "\nRequest: " .str_replace('>',">\n",$last_request);
print "\nResponse: ".str_replace('>',">\n",$last_response);
That way I got just that litle more information I needed! to:
2) enter password in the password field and the username in the user field
It works!
For those interested
Using the array structure and the 'new stdClass' both work
all three ways of parsing the call work (also the two commented out ones, use which one you like)
I am attempting to parse an RSS feed which uses media enclosures. I am using SimplePie and I have been able to parse it, and make all the needed elements appear on the page.
But I am writing a plugin for a CMS and I need to put those elements into an array. All are working fine, except the $item->get_enclosure().
I should say, that in the array, what is returned is a string of gibberish. I need it to return the url to the file.
Here is the relevant code:
// Get Enclosure
$enclosures = array();
$item_enclosures = $item->get_enclosures();
if ( ! empty($item_enclosures))
{
foreach ($item_enclosures as $enclosure)
{
if ($enclosure = $item->get_enclosure())
{
$enclosure->get_link();
} else {
$enclosure->get_title();
}
}
}
$items[] = array(
'item_title' => $item->get_title(),
'item_link' => $item->get_permalink(),
'item_date' => $item->get_date('U'),
'item_content' => $item->get_content(),
'item_img' => $item->get_enclosure(),
'item_description' => $item->get_description(),
'item_categories' => $categories,
'item_authors' => $authors
);
}
return $items;
Does anyone know how to make the 'item_img' return a link to the file, rather than what seems to be some kind of encoded string of characters.
From http://simplepie.org/wiki/reference/simplepie_enclosure/get_link
$link = $item->get_enclosure()->get_link();
would seem to do what you want.
I am new to php, I am using metro-websign for creating my website. There is a plugin taking an array. The following code works fine:
<? php
$photoNewsPath = array(
"photo/committees/spirit-rock/20150203-anna.jpg",
"photo/news/20150207 - 100 day.jpg"
);
$photoNewsTitle = array("Post your photos on the website", "100 school day = pajama day fun");
var_dump($photoNewsPath);
$tile[] = array(
"type" => "slideshow",
"images" => $photoNewsPath,
"classes" => "");
But when I read the array from an xml file:
<? php
$photonews = simplexml_load_file("config\photonews.xml") or die("Error: Cannot create object");
foreach($photonews - > news as $news) {
$photoNewsPath[] = (string) $news - > path;
}
var_dump($photoNewsPath);
$tile[] = array(
"type" => "slideshow",
"images" => $photoNewsPath,
"classes" => ""); ?>
the plugin doesn't work anymore. I use var_dump to dump the array from both code snippets. The results are identical. What could make the arrays different so the php plugin fails?
Any clues?
you have an error into foreach. this is the correct code to access at the
<path></path> tag into xml
<?php
$photonews = simplexml_load_file("config/photonews.xml") or die("Error: Cannot create object");
$photoNewsPath=array();
foreach($photonews as $key => $value) {
$photoNewsPath[]= (string) $photonews->path;
}
// var_dump($photoNewsPath);
$tile[] = array(
"type" => "slideshow",
"images" => $photoNewsPath,
"classes" => ""); ?>
Hi I'm trying to setup an api service with Limoanywhere system. But regardless of what I do I get invalid ApiKey & ApiID. I went into the back system and changed the ApiKey & ApiId multiple times but still no success.
Can anyone tell me if my code is correct?
<?php
$client = new SoapClient('https://qa.book.mylimobiz.com/api/ApiService.asmx?wsdl');
$options = array(
'ApiKey' => '***api key here****',
'ApiID' => '***api id here****'
);
$result = $client->__soapCall('Test', $options);
//var_dump($client->__getFunctions());
print_r($result);
?>
Here is the snippet from the service
http://qa.book.mylimobiz.com/api/ApiService.asmx?op=Test
Here is the result I get from when run my php code.
Array ( [TestResult] => Array ( [ResponseCode] => 1 [ResponseText] => Invalid ApiId or ApiKey ) )
Check this instead of test Test function not working giving error but test of the test all function are working.
<?php
$soapClient = new SoapClient("https://book.mylimobiz.com/api/ApiService.asmx?wsdl");
// Prepare SoapHeader parameters
$sh_param = array('apiId' => 'xxxxxx','apiKey' => 'xxxxxxxxxxxx');
$headers = new SoapHeader('https://book.mylimobiz.com/api/ApiService.asmx?wsdl', 'GetVehicleTypes', $sh_param);
// Prepare Soap Client
$trans = $soapClient->GetVehicleTypes($sh_param)->GetVehicleTypesResult;
echo "<pre>"; print_r($trans);
?>
Hi I'm making a web service in cakephp for an android app. I am getting the request and the respose is being send but the response is not visible on the client's end. My code is as shown below. Can there be some other method to send the response.
public function AndroidApp() {
if (isset($_POST["myHttpData"])) {
$coupon = trim($_POST["myHttpData"]);
$couponId = $this->Code->find('all', array(
'conditions' => array(
'Code.coupon_code' => $coupon,
'Code.status' => 'Used'
),
'fields' => array('Code.id')));
$studentAssessmentId = $this->StudentAssessment->find('all', array(
'conditions' => array(
'StudentAssessment.code_id' => $couponId[0]['Code']['id'],
'StudentAssessment.status' => 'Complete'
),
'fields' => array('StudentAssessment.id')));
$scores = $this->AssessmentScore->find('all', array(
'conditions' => array(
'AssessmentScore.student_assessment_id' => $studentAssessmentId[0]['StudentAssessment']['id']
),
'fields' => array('AssessmentScore.score')));
$json = array();
$assessment_data = array();
//debug($scores);
$i = 0;
foreach ($scores as $score) {
$assessment_data[$i] = array("score" => $score['AssessmentScore']['score']);
$i+=1;
}
header('Content-type: application/json');
$json['success'] = $assessment_data;
$android = json_encode($json);
} else {
$json['error'] = "Sorry, no score is available for this coupon code!";
$android = json_encode($json);
}
echo $android;
code smell, non-cakephp standards
First of all, as mentioned in comments by others, you're not using the CakePHP request/response objects. Because of this, you're overly complicating things. See the documentation here;
http://book.cakephp.org/2.0/en/controllers/request-response.html
http://book.cakephp.org/2.0/en/controllers/request-response.html#dealing-with-content-types
And
http://book.cakephp.org/2.0/en/views/json-and-xml-views.html
The $scores loop to reformat the query results is probably redundant if you replace the find('all') with find('list'), using 'score' as display field. See the documentation here http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#find-list
bugs
There also seems to be some bugs in your code;
the content-type header is only sent if $_POST["myHttpData"] is present.
you're only checking if $_POST["myHttpData"] is present, not if it actually contains any data (empty)
you're not checking if the various queries return a result. This will cause errors in your code if a query did not return anything! For example, you assume that $couponId[0]['Code']['id'] is present (but it won't be if the coupon-code was not found)
possible answer
Apart from these issues, the most probable cause for your problem is that you did not disable 'autoRender'. Therefore CakePHP will also render the view after you've output your JSON, causing a malformed JSON response.
public function AndroidApp() {
$this->autoRender = false;
// rest of your code here
}