PHP SoapClient WSDL DeserializationFailed Invalid enum value - php

I am trying to use SoapClient in PHP to retrieve data from a WSDL. If I use hardcoded values, then it works with zero errors:
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = $obj->{'LoginResult'};
$params2['VehicleClass'] = 'UsedCar';
$params2['ApplicationCategory'] = 'Consumer';
$params2['VersionDate'] = '2016';
$result2 = $client->GetMakes($params2);
I am getting the following error when I use variables or dynamic content:
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed
] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter
http://someURL/VehicleInformationService:VehicleClass
. The InnerException message was 'Invalid enum value 'UsedCars'
I have tried
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = $obj->{'LoginResult'};
$params2['VehicleClass'] = $VehicleClass;
$params2['ApplicationCategory'] = $ApplicationCategory;
$params2['VersionDate'] = $VersionDate;
$result2 = $client->GetMakes($params2);
I have also tried
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = (string) $obj->{'LoginResult'};
$params2['VehicleClass'] = (string) $VehicleClass;
$params2['ApplicationCategory'] = (string) $ApplicationCategory;
$params2['VersionDate'] = (string) $VersionDate;
$result2 = $client->GetMakes($params2);
I have also tried:
$SubmitData = new stdClass();
$SubmitData->AuthenticationKey = new SoapVar($obj->{'LoginResult'}, XSD_STRING);
$SubmitData->VehicleClass = new SoapVar($VehicleClass, XSD_STRING);
$SubmitData->ApplicationCategory = new SoapVar($ApplicationCategory, XSD_STRING);
$SubmitData->VersionDate = new SoapVar($VersionDate, XSD_STRING);
$result2 = $client->GetMakes($SubmitData);
Same error each time. I do not know how to get around "Invalid enum value" error
Thanks in advance

Related

Field missing for stdClass php

$resp = new stdClass();
$resp->first_name->type = "select";
$resp->first_name->required = 'true';
$resp->first_name->type_meta->options[0] = "opt 1";
$resp->first_name->type_meta->options[1] = "opt 2";
$resp->first_name->type_meta->options[2] = "opt 3";
$resp->last_name->type = "text";
$resp->last_name->required = 'true';
$resp->last_name->type_meta=new stdClass();
Why does my script won't work on my php file but works on w3schools php try it compiler. The error I get is
Fatal error: Uncaught Error: Attempt to assign property "type" on null
Even though I am using stdClass() to create an object so why it gives null for type field.
You need to create the sub-properties first. A property without a value is null, so you need to make it an stdClass as well and then you can go.
$resp = new stdClass();
$resp->first_name = new stdClass();
$resp->first_name->type = "select";
$resp->first_name->required = 'true';
$resp->first_name->type_meta = new stdClass();
$resp->first_name->type_meta->options[0] = "opt 1";
$resp->first_name->type_meta->options[1] = "opt 2";
$resp->first_name->type_meta->options[2] = "opt 3";
$resp->last_name = new stdClass();
$resp->last_name->type = "text";
$resp->last_name->required = 'true';
$resp->last_name->type_meta=new stdClass();
you need to set a value for $resp->first_name and $resp->last_name because there values is null or if you are using php 8 you can use null safer operator like this : $resp->first_name?->type = "select";

How do I get the serialized inventory item by the inventory id in NetSuite api with PHP?

Here is the situation, I'm trying to get the Serialized Inventory Item based on the id (https://xxx.app.netsuite.com/app/common/item/item.nl?id=522216), however, when I tried the following code:
$search = new TransactionSearchBasic();
$type = new SearchEnumMultiSelectField();
$type->operator = 'anyOf';
$type->searchValue = array('serializedInventoryItem');
$search->type = $type;
$invetoryRef = new RecordRef();
$invetoryRef->internalId = '522216';
$params = new SearchMultiSelectField();
$params->operator = 'anyOf';
$params->searchValue = array($invetoryRef);
$search->serializedInventoryItem = $params;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
However, the response that I'm getting the following error:
The field type's enum value is invalid for this search.
Why would I be getting that error message?
Thank you,
Kevin Davis

Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given,

I am unable to export my mysql table to XML format using PHP, I receive the following error when I run the below script. I have removed the connection bit, I have gone through already errors but was not able resolve this issue.
Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given,
Script:
<?php
$query = "SELECT id, name, plate, datetime , time , image_name FROM EarlsdonMSIN_anpr_vega";
$camArray = array();
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
array_push($camArray, $row);
}
if(count($camArray)){
createXMLfile($camArray);
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();
function createXMLfile($camArray){
$filePath = '/cam.xml';
$dom = new DOMDocument('1.0', 'utf-8');
$root = $dom->createElement('cam');
for($i=0; $i<count($camArray); $i++){
$camId = $camArray[$i]['id'];
$camName = $camArray[$i]['name'];
$camplate = $camArray[$i]['plate'];
$camdatetime = $camArray[$i]['datetime'];
$camtime = $camArray[$i]['time'];
$camimagename = $camArray[$i]['image_name'];
$cam = $dom->createElement('cam');
$cam->setAttribute('id', $camId);
$name = $dom->createElement('name', camName);
$cam->appendChild($name);
$plate = $dom->createElement('plate', $camplate);
$cam->appendChild($plate);
$datetime = $dom->createElement('datetime', $camdatetime);
$cam->appendChild($datetime);
$time = $dom->createElement('time', $camtime);
$cam->appendChild($time);
$imagename = $dom->createElement('image_name', $camimagename); $cam->appendChild($image_name);
$root->appendChild($cam);
}
$dom->appendChild($root);
$dom->save($filePath);
}

Php soap data send error

When sending data to the SomeMethod() method, the 1 excess parameter returns as an error.
My Code:
$client = new SoapClient('site_url/?wsdl');
$client->soap_defencoding = 'UTF-8';
$loginparam = array('userName'=>'name','password'=>'pass','trace' => 1, 'exceptions' => 0);
$session = $client->OturumAc($loginparam);
$SoapIcHeader = new SoapHeader("http://sanayi.gov.tr","TokenId",$session->OturumAcResult);
$client->__setSoapHeaders($SoapIcHeader);
$OturumUzat = $client->OturumDogrulaVeUzat($session ->OturumAcResult);
$param["BosAgirligi"] = "20";
$param["CalismaBasinci"] = "5";
$param["DoluAgirligi"] = "1";
$param["SonMuayeneTarihi"] = "2017-08-01 10:19:04";
$param["SonMuayeneYapanFirmaMersisNo"] = "123456789";
$param["SuKapasitesi"] = "1";
$param["TestBasinci"] = "10";
$param["DolumBasinci"] = "15";
$param["EtKalinligi"] = "3";
$param["ImalatTarihi"] = "2017-08-01 10:19:04";
$param["SeriNo"] = "123";
$param["TescilEdenTesisId"] = "31fd684c-f97d-48c1-a7fb-60f30f536d8d";
$param["UreticiId"] = "31fd684c-f97d-48c1-a7fb-60f30f536d8d";
// $param["UygunlukIsareti"] = "1";
$date = date('d/m/Y');
$id ="2ad9a9a9-adb9-4fb8-8fae-01e84aa72343";
try
{
$sonuc = $client->TupTescil($id,$date,$param);
print_r($sonuc);
}
catch (Exception $e)
{
echo "Error ! ";
echo $e -> getMessage ();
}
Return Error
Error ! The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'TupTescil'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 281.
This example works with C#
Guid tupKimligi = new Guid("07FAF194-4E80-4359-95D9-011CA1F5A1D4");
DateTime islemSaati = DateTime.Today;
TupTescilBilgisi tescilBilgileri = new TupTescilBilgisi()
{
BosAgirligi = 1,
CalismaBasinci = 1,
DoluAgirligi = 1,
SonMuayeneTarihi = DateTime.Today,
SonMuayeneYapanFirmaMersisNo = "123456789",
SuKapasitesi = 1,
TestBasinci = 1,
DolumBasinci = 1,
EtKalinligi = 1,
ImalatTarihi = DateTime.Today,
SeriNo = "123",
TescilEdenTesisId = tesisId,
UreticiId = ureticiId,
UygunlukIsareti = TupUygunlukIsareti.Pi
};
Tup tescilSonuc = tsc.TupTescil(tupKimligi, DateTime.Today, tescilBilgileri);
You can also look at the wsdl structure here
enter link description here
Thanks for your help

Not an object error

I've written this code for vTiger, trying to tie the Quote module into a field for the Lead module:
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
//(module name without space)
$module = Vtiger_Module::getInstance('Leads');
// Create Block instance
$block1 = new Vtiger_Block();
$block1->label = 'Block Name';
$block1 = Vtiger_Block::getInstance('LBL_LEAD', $module);
$field0 = new Vtiger_Field();
$field0->name = 'Leads';
$field0->label = 'Leads';
$field0->uitype = 10;
$field0->typeofdata = 'V~O';
$field0->setRelatedModules(Array('Quotes'));
$block1->addField($field0);
This is the response I'm getting:
Setting Leads relation with Quotes ... DONE
Fatal error: Call to a member function addField() on a non-object in /var/www/duvtiger/vtigerscript.php on line 23
Why is $block1 not an object?
How do I fix this? What am I doing wrong? This is all I have to do to setup the related field, correct?
try this code to add new related field. This will surely helps you. You have set relation before adding field that's why the error you getting is "block1 is not an object".
$field0 = new Vtiger_Field();
$field0->name = 'quotes';
$field0->column = 'quotes';
$field0->table = $module->basetable;
$field0->label = 'Test2';
$field0->uitype = 10;
$field0->typeofdata = 'V~O';
$block1->addField($field0);
$field0->setRelatedModules(Array('Quotes'));

Categories