First time using the PHP SOAP client - php

I've started writing some code to use SOAP within PHP.
Managed to get my code to login and authenticate, which is a start!
I initially had the following code :
$params = array(
"Parcels" => 1,
"RecipientAddress" => "123 Any Street, Any Town, Anywhere",
"RecipientName" => "Joe Bloggs",
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
// Print WS response
var_dump($response);
Which returned the following message :
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Missing Recipient Address Element 'RecipientName' in /home/thisone/public_html/despatchbayservices.php:17 Stack trace: #0 /home/thisone/public_html/despatchbayservices.php(17): SoapClient->__soapCall('GetAvailableSer...', Array) #1 {main} thrown in /home/thisone/public_html/despatchbayservices.php on line 17
I've tried changing the code to :
$params = array(
"Parcels" => 1,
"RecipientAddress" => array(
"RecipientName" => "Joe Bloggs",
),
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
// Print WS response
var_dump($response);
Which returned this :
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'RecipientAddress' property in /home/thisone/public_html/despatchbayservices.php:18 Stack trace: #0 /home/thisone/public_html/despatchbayservices.php(18): SoapClient->__soapCall('GetAvailableSer...', Array) #1 {main} thrown in /home/thisone/public_html/despatchbayservices.php on line 18
I'm sure I'm doing something really stupid but I just cant see it - any help massively appreciated!

Sussed it - thanks to Don't Panic for pointing me toward the WDSL.
For reference the correct/working code is :
$params = array(
"Parcels" => array(
"ParcelType" => array(
"Weight" => 5,
"Length" => 5,
"Width" => 5,
"Height"=> 5,
)
),
"RecipientAddress" => array(
"RecipientName" => "Joe Bloggs",
"RecipientAddress" => array(
"CompanyName" => "My Company",
"Street" => "123 Any Street",
"Locality" => "Anywhere",
"TownCity" => "Any Town",
"County" => "Somewhere",
"PostalCode" => "TS23 4EA",
"CountryCode" => "GB",
)
),
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));

Related

Why did my SOAP request start returning error

I'm trying to make a SOAP request with TNT's webservice, but I'm getting an error and I don't know what to do.
There is my code:
$client = new SoapClient('http://ws.tntbrasil.com.br:81/tntws/CalculoFrete?wsdl');
$function = 'calculaFrete';
$parameters = array('calculaFrete' => array('in0' => array(
'cdDivisaoCliente' => 1,
'cepDestino' => '36213000',
'cepOrigem' => '36213000',
'login' => 'gerencia#uaiartesanatos.com.br',
'nrIdentifClienteDest' => '00000000000',
'nrIdentifClienteRem' => '29026107000190',
'nrInscricaoEstadualDestinatario' => '0000000000000',
'nrInscricaoEstadualRemetente' => '0030746110022',
'psReal' => 15,
'senha' => '',
'tpFrete' => 'C',
'tpPessoaDestinatario' => 'F',
'tpPessoaRemetente' => 'J',
'tpServico' => 'RNC',
'tpSituacaoTributariaDestinatario' => 'CO',
'tpSituacaoTributariaRemetente' => 'CO',
'vlMercadoria' => 650.17,
)));
$result = null;
$result = $client->__soapCall($function, $parameters);
and i'm getting this error
Fatal error: Uncaught SoapFault exception: [ns0:Server] java.lang.NullPointerException in C:\xampp\htdocs\tnt\index.php:27 Stack trace: #0 C:\xampp\htdocs\tnt\index.php(27): SoapClient->__soapCall('calculaFrete', Array) #1 {main} thrown in C:\xampp\htdocs\tnt\index.php on line 27
I've been using it since 2018, but in recent weeks this error has started to occur, does anyone know what is going on ??
I thank you all for your help
The error is coming from the webservice.
java.lang.NullPointerException is a exception thrown by Java.
It may be some update that broke the webservice, some new parameter that you are not sending or some wrong parameter.
I suggest you to get in touch with the webservice owners.

PHP Soapclient returns object has no property

When sending a request from my PHP soapclient as described below, I get:
[getInterestAndExchangeRates failed: Please check inparameters in Xxx].
I suspect that it is the [$response] line that has wrong syntax. More specific the [$searchRequestParameters]. I have checked that all the content in the array is in the correct order.
Question:
Is there something wrong with below code syntax?
I have followed following instructions:
https://swea.riksbank.se/sweaWS/docs/api/call/getInterestAndExchangeRates.htm
<?php
/**
* A soapclient request to Swedish Central bank, API.
*/
$client = new SoapClient("https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl");
$searchGroupSeries = array(
"groupid" => 2,
"seriesid" => "SECBREPOEFF"
);
$searchRequestParameters = array (
"aggregateMethod" => "W",
"avg" => true,
"datefrom" => "2018-01-01",
"dateto" => "2019-01-01",
"languageid" => "en",
"max" => true,
"min" => false,
"searchGroupSeries" => $searchGroupSeries,
"ultimo" => false
);
// Test 1 (pointing out above array, does not work):
$response = $client->__soapCall("getInterestAndExchangeRates", $searchRequestParameters);
// Test 2 (wrap in above array inside another array, does not work):
// $response = $client->__soapCall('getInterestAndExchangeRates', array('searchRequestParameters' => $searchRequestParameters));
var_dump($response);
Error:
PHP Fatal error: Uncaught SoapFault exception: [soap:Server] getInterestAndExchangeRates failed: Please check inparameters in [path]_(does_not_work).php:22
Stack trace:
#0 [path]_(does_not_work).php(22): SoapClient->__soapCall('getInterestAndE...', Array)
#1 {main}
thrown in [path]_(does_not_work).php on line 22

Uncaught ActiveRecord\UndefinedPropertyException codeigniter

I am new to codeigniter I am trying to save my record into the database and when ever I try to do so it gives me this error.
Fatal error: Uncaught ActiveRecord\UndefinedPropertyException: Undefined property: Product->Array in C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php on line 514 in C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php:514 Stack trace: #0 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php(333): ActiveRecord\Model->read_attribute('Array') #1 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Validations.php(573): ActiveRecord\Model->__get('Array') #2 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Validations.php(141): ActiveRecord\Validations->validates_uniqueness_of(Array) #3 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php(1048): ActiveRecord\Validations->validate() #4 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php(784): ActiveRecord\Model->_validate() #5 C:\xampp\htdocs in C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php on line 514
The code I have wrote works fine for other models. Here is the code I am using.
$data = array(
"type" => $this->input->post('type'),
"code" => $this->input->post('code'),
"name" => $this->input->post('name'),
"category" => $this->input->post('category'),
"cost" => $this->input->post('cost'),
"description" => $this->input->post('description'),
"tax" => $this->input->post('tax'),
"alertqt" => $this->input->post('alertqt'),
"price" => $this->input->post('price'),
"color" => $this->input->post('color'),
"supplier" => $this->input->post('supplier'),
"unit" => $this->input->post('unit'),
"taxmethod" => $this->input->post('taxmethod'),
"options" => $this->input->post('options'),
"photo" => $image,
"photothumb" => $image_thumb,
"created_at" => $date,
"modified_at" => $date
);
$product = Product::create($data);
I have solved it the issue was not in the controller but it was in the model. I was validating uniqueness of array but actually it was not needed. Removing that block of code works fine.

Ride reminder api 404 error

When we are calling Uber Products API, its working perfect but when we call Ride Reminder API, we getting following 404 errors:
PHP Fatal error: Uncaught exception GuzzleHttp\Exception\ClientException
with message
Client error: POST https://sandbox-api.uber.com/v1.2/reminders
resulted in a 404 Not Found response:
404 page not found in
/var/www/html/uber/uber/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /var/www/html/uber/uber/vendor/guzzlehttp/guzzle/src/Middleware.php(65):
GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request),
Object(GuzzleHttp\Psr7\Response))
#1 /var/www/html/uber/uber/vendor/guzzlehttp/promises/src/Promise.php(203):
GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /var/www/html/uber/uber/vendor/guzzlehttp/promises/src/Promise.php(156):
GuzzleHttp\Promise\Promise::callHandler(1,
Object(GuzzleHttp\Psr7\Response), Array)
#3 /var/www/html/uber/uber/vendor/guzzlehttp/promises/src/TaskQueue.php(47):
GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}()
#4 /var/www/html/uber/uber/vendor/guzzlehttp/promises/src/Promise.php(246):
Guzzle in
/var/www/html/uber/uber/vendor/stevenmaguire/uber-php/src/Client.php
on line 173
We are using following sample code to work out, let me know what could be issue.
<?php
include "vendor/autoload.php";
$client = new Stevenmaguire\Uber\Client(array(
'access_token' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'server_token' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'use_sandbox' => true, // optional, default false
'version' => 'v1.2', // optional, default 'v1.2'
'locale' => 'en_US', // optional, default 'en_US'
));
$products = $client->getProducts(array(
'latitude' => '41.85582993',
'longitude' => '-87.62730337'
));
var_dump($products);
$attributes = array(
'reminder_time' => '1429294463',
'phone_number' => '555-555-5555',
'event' => array(
'time' => '1515750429',
'name' => 'John with friends',
'location' => 'Dolores Park',
'latitude' => '37.759773',
'longitude' => '-122.427063',
'product_id' => "737d4e43-9e12-4a81-add3-acb101bab4c7",
),
);
$reminder = $client->createReminder($attributes);
var_dump($reminder);
Please help us to fix this.
Documentation is removed for ride reminders from http://developer.uber.com and they are not currently supported.

How to set up a Mapping while indexing data through bulk API in Elasticsearch-PHP?

I am trying to follow this tutorial, and I need to do it in PHP, so I have to use Elasticsearch-php. In this particular step, I am trying to set up a mapping for elasticsearch and also bulk index data from a .json file. So I looked into examples here and [here][3], and following is my code.
The problem is taht it gives me
Elasticsearch PHP client created successfully!
Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Action/metadata line [1] contains an unknown parameter [dynamic]"}],"type":"illegal_argument_exception","reason":"Action/metadata line [1] contains an unknown parameter [dynamic]"},"status":400} in /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:610 Stack trace: #0 /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(273): Elasticsearch\Connections\Connection->process4xxError(Array, Array, Array) #1 /var/www/html/Tests/Test/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array) #2 /var/www/html/Tests/Test/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(Object(Closure), NULL, NULL) #3 /var/www/html/Tests/Test/vendor/guzzlehttp/ringphp/src/ in /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 610
and when I comment out the line "dynamic" => "false", I get
Elasticsearch PHP client created successfully!
Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Malformed action/metadata line [1], expected a simple value for field [properties] but found [START_OBJECT]"}],"type":"illegal_argument_exception","reason":"Malformed action/metadata line [1], expected a simple value for field [properties] but found [START_OBJECT]"},"status":400} in /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:610 Stack trace: #0 /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(273): Elasticsearch\Connections\Connection->process4xxError(Array, Array, Array) #1 /var/www/html/Tests/Test/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array) #2 /var/www/html/Tests/Test/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(O in /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 610
What am I missing? How should I fix this?
<?php
require_once("vendor/autoload.php");
use Elasticsearch\ClientBuilder;
$esClient = ClientBuilder::create()->build();
echo "Elasticsearch PHP client created successfully!<br>";//check
$indexParams = array();
$indexParams['index'] = "test_packets_index";
$indexParams['type'] = "testPacketsType";
$indexParams['body'] = [
'mappings' => [
"testPacketsType" => [
//"dynamic" => "false",
"properties" => [
"timestamp" => [
"type" => "date"
],
"layers" => [
"properties" => [
"ip" => [
"properties" => [
"ip_ip_src" => [
"type" => "ip"
],
"ip_ip_dst" => [
"type" => "ip"
]
]
]
]
]
]
]
]
];
$jsonFileHandle = fopen("packets.json", "r");
if ($jsonFileHandle) {
while ( ($line = fgets($jsonFileHandle)) !== FALSE ) {
if ( !($line == "") ) {
$indexParams['body'][] = json_decode($line, true);
}
}
}
fclose($jsonFileHandle);
#print_r($indexParams['body']);//check
$indexingResponse = $esClient->bulk($indexParams);
echo "Result: "; print_r($indexingResponse); echo "<br>";//check
?>
[3]: https : //www.elastic.co/guide/en/elasticsearch/client/php-api/current/_indexing_documents.html

Categories