Why php's soapCall gives string conversion error? - php

// Set username and password
$ih_soap_user= $this->config->item('interUser');
$ih_soap_pass=$this->config->item('interPass');
//echo $ih_soap_user.':P:'.$ih_soap_pass;
// Set soap namespace
$ih_soap_ns = 'http://www.interhome.com/webservice';
// Create new instance of SoapClient with the interhome web service URL
$client = new
SoapClient($this->config->item('interSoap'),array('trace'=>'1'));
// Create new soap header and set username and password
$header = new SoapHeader($ih_soap_ns,
'ServiceAuthHeader',
array('Username' => $ih_soap_user,'Password' =>
$ih_soap_pass),
true
);
// Prepare p// Prepare parameters
$params = array('inputValue' =>array(
'Page'=>$page,
'PageSize'=>'10',
'OrderDirection'=>'Ascending',//Descending
'OrderBy'=>'Price',//Favorite,Place
'LanguageCode'=>'EN',
'CurrencyCode'=>'EUR',
'CountryCode'=>trim($ajaxSearchCountryCode),
'RegionCode'=>trim($ajaxSearchRegionCode),
'PlaceCode'=>$ajaxSearchPlaceCode,
'CheckIn'=> $ajaxSearchCheckinDate,
'Duration'=>'7',
'ThemeFilter'=>$ajaxSearchTheme,
'HouseApartmentType'=>array('House'=>'House'),
'SpecialOffer'=>'AnySpecialOffer',
'PaxMin'=>'1',
'PaxMax'=>'',
'RoomsMin'=>'1',
'RoomsMax'=>'',
) );
try{
$result = $client->__soapCall("Search",array('parameters'=> $params),null,$header);
Hi guys..Any Idea why this call when I pass any not empty array, as for example ,as I made for 'HouseApartmentType', returns this error
A PHP Error was encountered
Severity: Notice Message:
Array to string conversion
Filename:
controllers/houses.php Line
Number: 269
And when it's only empty array or a string the soap call function is working... I need to pass array of options to one parameter....
LINE 269 is
$result = $client->__soapCall("Search",array('parameters'=> $params),null,$header);

This is probably solved already, but I also had problems with this and I thought I should post here when I finally found the solution. (The solution is not nusoap, it throws the same error.)
The error only seems to come from the soapCall call generation, it really is the Web Service that causes it. When you run __soapCall, it first asks the server which datatypes the parameters should have and then tries to comply. So if you try to feed an array when the service expects a string, it will do the array to string conversion when the request is generated.

i think you should look at the manual how a soapcall work:
$params = array(
'Page'=>$page,
'PageSize'=>'10',
'OrderDirection'=>'Ascending',//Descending
'OrderBy'=>'Price',//Favorite,Place
'LanguageCode'=>'EN',
'CurrencyCode'=>'EUR',
'CountryCode'=>trim($ajaxSearchCountryCode),
'RegionCode'=>trim($ajaxSearchRegionCode),
'PlaceCode'=>$ajaxSearchPlaceCode,
'CheckIn'=> $ajaxSearchCheckinDate,
'Duration'=>'7',
'ThemeFilter'=>$ajaxSearchTheme,
'HouseApartmentType'=>'House', // changed to string instead of array
'SpecialOffer'=>'AnySpecialOffer',
'PaxMin'=>'1',
'PaxMax'=>'',
'RoomsMin'=>'1',
'RoomsMax'=>'' );
i simplified the array and you should test it and look if this is the kind of result you are looking for.
Also look for ordering errors like the example shown in php.net

Related

Docusign API PHP TemplatesApi::updateDocument FORMAT_CONVERSION_ERROR

I'm trying to update a template document via PHP API using this: https://github.com/docusign/docusign-php-client/blob/master/src/Api/TemplatesApi.php#L4946
I get one of two errors depending on if I set the apply_document_fields option.
Without it set, I get UNSPECIFIED ERROR Value cannot be null.\r\nParameter name: fileBytes. However, if I view the request body before sending, document_base_64 is set as expected.
With apply_document_fields set 'true' (actual boolean value is not supported), I get FORMAT_CONVERSION_ERROR The data could not be converted.
Either way, it seems like the document data is not getting sent correctly, but I can't figure out how I'm supposed to be sending it. Here's my code:
public static function updateTemplateWithDocument(string $documentId, string $templateId, $documentBody = null)
{
$api = My_Service_Docusign::getInstance();
$templatesApi = new DocuSign\eSign\Api\TemplatesApi($api->getAuth());
$document = new \DocuSign\eSign\Model\Document();
$document->setDocumentBase64(base64_encode($documentBody));
// Got an error reusing $documentId, so I'm incrementing it now
$document->setDocumentId((string) (((int)$documentId) + 1));
$def = new DocuSign\eSign\Model\EnvelopeDefinition();
$def->setDocuments(array($document));
$opts = new \DocuSign\eSign\Api\TemplatesApi\UpdateDocumentOptions();
// Different behavior with this set vs not
$opts->setApplyDocumentFields('true');
$res = $tmpApi->updateDocument($api->getAccountId(), $documentId, $templateId, $def, $opts);
return $res;
}
Unfortunately, DocuSign support doesn't support their API :-(
I figured out I need to use TemplatesApi::updateDocuments (plural) instead, which also allows me to reuse the documentId.

Warning: Illegal string offset 'code' in /path/ on line 17

I keep getting the error "Warning: Illegal string offset 'code' in /path/ on line 17". I have tried many things but don't know what the problem is. Here is my code:
require_once 'unirest-php-master/src/Unirest.php';
$response = Unirest\Request::post("https://andruxnet-random-famous-
quotes.p.mashape.com/?cat=movies",
array(
"X-Mashape-Key" => "key",
"Content-Type" => "application/x-www-form-urlencoded",
"Accept" => "application/json"
)
);
$encoded = json_encode($response,true);
echo $encoded['code'];
This code is being used to get information from the api and it is successfully getting the information but when I try to access an object in the array I get an error.
I have also tried to use json_decode instead of encode but that gives me an error about parameter 1 needing to be a string
Edit: line 17 is this line: echo $encoded['code'];
From your code, it seems like you want to print the response obtained from API (in JSON format). So, you should be doing json_decode here.
var_dump($response); // Check response obtained from API
$encoded = json_decode($response,true); // Change to json_decode
echo "<pre>"; print_r($encoded); // Debug decoded array
echo $encoded['code']; // Check data
I have resolved the issue. The first thing I did wrong was try to decode or encode it, I didn't need to do either. I was also using ["code"] rather than ->code

SOAP-ERROR: When using Enterprise Client for SalesForce

I am attempting to pass a custom field via a SOAP Client to SalesForce, here's my existing code:
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
$leadConvert = new stdClass;
$leadConvert->leadId = $eLEADID;
$leadConvert->Custome_field = true;
$leadConvertArray = array($leadConvert);
echo "<pre>";
print_r($leadConvertArray);
echo "</pre>";
$leadConvertResponse = $mySforceConnection->convertLead($leadConvertArray);
echo "<pre>";
print_r($leadConvertResponse);
echo "</pre>";
}
catch (Exception $e) {
echo $e->faultstring;
}
The way it's being passed to SOAP is this:
Array
(
[0] => stdClass Object
(
[leadId] => XXXXXXXXXX
[Custom_field] => 1
)
)
And my error that I am getting is as follows:
SOAP-ERROR: Encoding: object has no 'convertedStatus' property
Do I have to set something in the WSDL in order for this to work? This is to attempt to update a leadID in SalesForce to have it be converted to account/opportunity.
Is there a better way for me to debug this and see what I am missing maybe from the WSDL?
Note: the error means that you "literally" don't have the parameter set in the request. To fix it, simply pass what it's complaining about.
New Issue:
After adding the request, I am getting the following error:
Element {urn:enterprise.soap.sforce.com}Custome_field invalid at this location
Not quite sure what that error means at all. Any thoughts?
For the error:
Element {urn:enterprise.soap.sforce.com}Custome_field invalid at this location
It appears you are trying to set a custom field on the Lead record to a boolean value.
Custom fields in Salesforce will typically end with the __c suffix.
Check the API name for the field in Salesforce and ensure the user who generated and is accessing the Enterprise API has field level access to it.
Then you code should be something like:
$leadConvert->Custom_field__c = true;
It also seems a bit odd that you are setting a custom field for a Lead and then passing it to the convertLead() web method. See the LeadConvert Arguments, which include convertedStatus.

json from string to array using php

I have a problem with json parsing.
I have already read the many questions here on stackoverflow but I can't figured out what I'm missing.
In my site I use Facebook Api to post my feed using curl and it respond with a json message.
I take this response and I save it in my database.
In my Backoffice I need to retrieve this message and print it in case of error.
Here an example about an error message:
{"error":{"message":"(#1500) The url you supplied is invalid","type":"OAuthException","code":1500}}
In my php page I need to get just the message part so I did:
$message = get from the db and fetch;
$error_array = json_decode($message,true);
print_r($error_array);
but it doesn't print anything, just a blank page.
If I just print $message I can see the entire string.
What am I missing?
This issue it's driving me crazy all day long!!
I tried the following:
<pre>
<?php
$jsonStr = '{"error":{"message":"(#1500) The url you supplied is invalid","type":"OAuthException","code":1500}}';
$error_array = json_decode($jsonStr, true);
print_r($error_array);
?>
and getting output:
Array
(
[error] => Array
(
[message] => (#1500) The url you supplied is invalid
[type] => OAuthException
[code] => 1500
)
)
It's working as intended.
I suspect the problem is with this:
$message = get from the db and fetch;
After you load the $message variable, do a var_dump($message) and see if the string is in there (as expected).
$jsonString = '["m#gmail.com","b#gmail.com","c#gmail.com"]';
$arrayOfEmails=json_decode($jsonString);
Or
$jsonString = "[\"a#gmail.com\",\"b#gmail.com\",\"c#gmail.com\"]";
$arrayOfEmails=json_decode($jsonString);

net.sf.jasperreports.engine.design.JRValidationException - Query parameter not found

I use JasperServer and PHP JavaBridge to generate PDF reports via JasperServer inside PHP. I get compile error because of missing (unassigned) parameter passed to JRXML compiler
Fatal error: Uncaught [[o:Exception]:
"java.lang.Exception: Invoke failed:
[[c:JasperCompileManager]]->compileReport((o:String)[o:String]).
Cause: net.sf.jasperreports.engine.design.JRValidationException:
**Report design not valid** : 1. **Query parameter not found** : db_field_id VM:
1.6.0_18#http://java.sun.com/" at: #-12
net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:258)
I cant find a way to pass my
$params = new Java("java.util.HashMap");
foreach ($jrxml_params as $key => $jr_param) $params->put($key, $jr_param);
list of params to the compile method nor I can disable this verification by
$japser_props = new JavaClass("net.sf.jasperreports.engine.util.JRProperties");
$japser_props->COMPILER_XML_VALIDATION = false;
Here is what I use to generate PDF (works fine if JRXML file doesn't contain $P{} pamareters and halts otherwise)
$class = new JavaClass("java.lang.Class");
$class->forName("com.mysql.jdbc.Driver");
$driverManager = new JavaClass("java.sql.DriverManager");
$conn = $driverManager->getConnection("jdbc:mysql://localhost:3306/XXX?user=XXX&password=1234");
$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
$report = $compileManager->compileReport(realpath("/www/some.jrxml"));
$params = new Java("java.util.HashMap");
foreach ($jrxml_params as $key => $jr_param) $params->put($key, $jr_param);
$jasperPrint = $fillManager->fillReport($report, $params, $conn);
$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
$outputPath = realpath(".")."/"."output.pdf";
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
How do I avoid this error, I know what I need to pass and I don't know a way to do it, can't I just pass params to fillManager?
$japser_props = new JavaClass("net.sf.jasperreports.engine.util.JRProperties");
$japser_props->setProperty('net.sf.jasperreports.compiler.xml.validation',true);
this is the way to set property from PHP but that's not the problem. It turns out everything was fine, I've missed parameter declaration before my MySQL query... Put
<parameter name="db_field_id" class="java.lang.Integer">
in your JRXML before you use it as $P{db_field_id} now it compliles fine and later
$jasperPrint = $fillManager->fillReport($report, $params, $conn);
parameters are assigned at fill time

Categories