I need to send a SOAP request that contains an element that repeats.
$params = array(
'UpdatedShipment' => array(
'OriginalShipDate'=>'2020-11-01',
'ShipmentInfo'=>array(
'Account' => 'XXXXX',
'ShipmentIdentificationNumber'=>'XXXXXXX',
'ServiceType'=>'P',
'PaperlessTradeEnabled'=>'1',
'SpecialServices'=>array(
'Service'=>array(
'ServiceType'=>'WY'
)
),
'IncludePreviousPieceLabels'=>'Y',
'DocumentImages'=> array(
'DocumentImage'=>array(
array('DocumentImageType'=>'INV','DocumentImage'=>base64_encode('xxxxxx'),'DocumentImageFormat'=>'PDF'),
array('DocumentImageType'=>'DCL','DocumentImage'=>base64_encode('xxxxxx'),'DocumentImageFormat'=>'PDF'),
)
)
),
)
);
$result = $s->UpdateShipmentRequest((array)($params));
It throws an exception:
SOAP-ERROR: Encoding: object has no 'DocumentImage' property
This is WSDL
https://wsbexpress.dhl.com/sndpt/updateShipment?WSDL
How can i resolve this?
Thanks
Related
I am trying to consume soapclient based API of https://developer.signicat.com/documentation/signing/get-started-with-signing/full-flow-example/
There are tow methods of it
1- you have to upload a document and it returns you an SDS ID, this part works fine
2- then you need to use this SDS ID in second part of API to create a sign request method name is createRequest(),
This is where I am getting problem, I have passed all the parameters but still getting an error on one parameter which is xsi:type I am not sure how to pass this parameter from php array.
Here is the sample XML
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ref-sds-id="090520195vbxk9uuw4dks9tjm2pmpy7sx3na397xz6qclxtepaslnb00q7" send-to-archive="false" xsi:type="sds-document">
<sign-text-entry/>
<description>Loan contract.pdf</description>
</document>
here xsi:type="sds-document" this part is causing the issue
My Code:
$url = 'https://preprod.signicat.com/ws/documentservice-v3?wsdl';
$soap_setting = array(
"trace" => 1,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS + SOAP_USE_XSI_ARRAY_TYPE
);
$client = new SoapClient($url,$soap_setting);
$subject_type = $client->__getTypes();
$functions = $client->__getFunctions();
$subject = array(
'national-id'=> '198003010306',
'first-name' => 'Oskar',
'last-name' => 'Johansson',
'email' => 'kamran#creativerays.com'
);
$notification = array(
'recipient' => 'http://localhost/sign/php/',
'type' => 'URL',
'message' => 'Please seign ${taskUrl}',
'header'=> 'Test',
'notification-id' => '001'
);
$sdsdocument = array(
'ref-sds-id' => '100520193oz5vev0onyueul43ury4vz8g1hsnhr7w69pcwnoan96ojbtbb',
'send-to-archive' => true,
'description'=> 'test',
'sign-text-entry'=> 'test',
'xsi:type' => 'sds-document'
);
$documentaction = array(
'document'=> $sdsdocument,
'type'=> 'sign',
'optional'=> true,
'send-result-to-archive'=> true
);
$tasks = array(
'subject'=> $subject,
'document-action'=> $documentaction,
'notification'=> $notification,
'on-task-postpone'=> 'http://localhost/sign/php/?requestId=${requestId}&taskId=${taskId}&status=taskpostponed',
'on-task-complete'=> 'http://localhost/sign/php/?requestId=${requestId}&taskId=${taskId}&status=taskcomplete',
'on-task-cancel'=> 'http://localhost/sign/php/?requestId=${requestId}&taskId=${taskId}&status=taskcancelled',
'configuration'=> 'default',
'signature' =>array('method'=>'nbid-sign'),
'id'=> 'task00001',
'bundle'=> False
);
$request = array(
'language'=> 'en',
'task'=> $tasks
);
$tparam = array(
'service'=>'demo',
'password'=>'Bond007',
'request' =>$request
);
$create = $client->createRequest($tparam);
echo '<pre>';
print_r($create);
echo $client->__getLastRequestHeaders();
echo '</pre>';
The Error I am getting:
Fatal error: Uncaught SoapFault exception: [soap:Client] Failed to register new document action request: Document with id null must have subtype archive-document, sds-document, result-document, upload-document or provided-document
A SOAP request XML looks like the following:
<soapenv:Body>
<net:GetAvailability>
<net:request>
<inh:UserCredentials>
<inh:AgentID>**</inh:AgentID><inh:Password>**</inh:Password>
<inh:Username>**</inh:Username>
</inh:UserCredentials>
<net:AccessCircuit>
<arr:string>All</arr:string>
</net:AccessCircuit>
<net:RequestDetails xsi:type="net:TelephoneNumberAvailabilityRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<net:PerformMPFACCheck>No</net:PerformMPFACCheck>
<net:ProxyCLI>true</net:ProxyCLI>
<net:TelephoneNumber>0121****</net:TelephoneNumber>
</net:RequestDetails>
<net:UserConsent>Yes</net:UserConsent>
</net:request>
</net:GetAvailability>
</soapenv:Body>
What I need to do is send this XML request using PHP SOAP however im not able to get this working. My current code is as follows:
$APIParameters = array(
'request' => array(
'UserCredentials' => array(
'Username' => $this->apiUsername,
'Password' => $this->apiPassword,
'AgentID' => $this->apiResellerID,
),
'AccessCircuit' => array(
'string' => 'All'
),
'UserConsent' => 'Yes',
)
);
$APIParameters['request']['RequestDetails'] = new SoapParam( array('PerformMPFACCheck' => 'Yes', 'Postcode' => "****", 'ProxyCLI' => "true", 'TelephoneNumber' => '****'), "TelephoneNumberAvailabilityRequest");
print_r($APIParameters);
$apiResult = $SOAPClient->GetAvailability($APIParameters);
The print_r() returns the following:
Array
(
[request] => Array
(
[UserCredentials] => Array
(
[Username] => ****
[Password] => ****
[AgentID] => ****
)
[AccessCircuit] => Array
(
[string] => All
)
[UserConsent] => Yes
[RequestDetails] => SoapParam Object
(
[param_name] => TelephoneNumberAvailabilityRequest
[param_data] => Array
(
[PerformMPFACCheck] => Yes
[Postcode] => ****
[ProxyCLI] => true
[TelephoneNumber] => 0121****
)
)
)
)
Yet the SOAP request fails with a Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault]. What am I doing wrong?! Appreciate any help!
first check that your wsld soap access granted using this code
<?php
// enter your url
$client = new SoapClient('enteryoururl');
var_dump($client->__getFunctions());
?>
then check which function have in this url if you have access and your function list show your function then try this
Fatal error: Uncaught SoapFault exception: [ns1:Client.AUTH_1] Authentication Failed
I'm trying to use nuSOAP to send a array with some data that will be use it on DB, but every time i get this "wsdl error: XML error parsing WSDL issue ... not well-formed (invalid token)" on my client.php
Here is my a little of my code on the server :
$server->register('cadastrar',
array('dados'=>'tns:cadastro'),
array('return'=>'xsd:string'),
$namespace,
$namespace.'#cadastrar',
'rpc',
'encoded',
''
);
$server->wsdl->addComplexType('cadastrar', 'complexType', 'struct', 'all','',
array(
'empresa' =>array ('name'=>'empresa','type'=>'xsd:string')
,'nome' =>array ('name'=>'nome','type'=>'xsd:string')
,'email' =>array ('name'=>'email','type'=>'xsd:string')
,'ddd' =>array ('name'=>'ddd','type'=>'xsd:string')
,'tel' =>array ('name'=>'tel','type'=>'xsd:string')
,'msg' =>array ('name'=>'msg','type'=>'xsd:string')
)
);
function cadastrar($dados){
//$objCliente = new Cliente();
//if($objCliente)
//$id = $objCliente->cadastroWebService($dados);
return $dados['empresa'];
}
and this is my code on the client :
$dados = array(
'empresa' => $_POST['empresa'],
'nome' => $_POST['nome'],
'email' => $_POST['email'],
'ddd' => $_POST['ddd'],
'tel' => $_POST['tel'],
'msg' => $_POST['msg']
);
//Chama o metodo call do SOAP
$result = $client->call('cadastrar', array('cadastro'=> $dados));
Anybody got any idea why isn't working ?
Thanks
I found what i was doing wrong when i was iniciating the client i was missing some arguments...
$client = new nusoap_client('http://www.domain.com/server.php?wsdl&debug=1', 'wsdl');
I just put the wsdl&debug=1', 'wsdl' and it work it
I am currently building a e-mail client (inbound and outbound sending) using Mandrill as the e-mail sending / inbound service and Laravel 3.x.
In order to send messages, I am using the HTTPful bundle with the Mandrill using the following code in my mail/compose POST method.
$url = 'https://mandrillapp.com/api/1.0/messages/send.json';
$data = array(
'key' => '{removedAPIkey}',
'message' => array (
'to' => array( array( "email" => $_to ) ),
'from_name' => Auth::user()->name,
'from_email' => Auth::user()->email,
'subject' => $_subject,
'html' => $_body
),
'async' => true
);
$request = Httpful::post($url)->sendsJson()->body($data)->send();
Link to better formatted code above: http://paste.laravel.com/m79
Now as far as I can tell from the API log, the request is correctly made (with the expected JSON) and a response of the following format is sent back:
[
{
"email": "test#test.com",
"status": "queued",
"_id": "longmessageID"
}
]
However, what I am trying to do is access the response from the request (specifically the _id attribute), which is in JSON. Now as far as I'm aware, the HTTPful class should do this automatically (using json_decode()). However, accessing:
$request->_id;
is not working and I'm not entirely sure how to get this data out (it is required so I can record this for soft-bounce, hard-bounce and rejection messages for postmaster-like functionality)
Any assistance would be appreciated.
Edit
Using the following code, results in the mail being sent but an error returned:
$url = 'https://mandrillapp.com/api/1.0/messages/send.json';
$data = array(
'key' => '{removedAPIkey}',
'message' => array (
'to' => array( array( "email" => $_to ) ),
'from_name' => Auth::user()->name,
'from_email' => Auth::user()->email,
'subject' => $_subject,
'html' => $_body
),
'async' => true
);
$request = Httpful::post($url)->sendsJson()->body($data)->send();
if ( $request[0]->status == "queued" ) {
$success = true;
}
Results in an exception being thrown: Cannot use object of type Httpful\Response as array
I must say, a huge thanks to Aiias for his assistance. I managed to fix this myself (I must have spent hours looking at this). For anyone who wants to know, the HTTPful bundle has a body array, where the response is kept. Therefore, the code below works:
$url = 'https://mandrillapp.com/api/1.0/messages/send.json';
$data = array(
'key' => '{removedAPIkey}',
'message' => array (
'to' => array( array( "email" => $_to ) ),
'from_name' => Auth::user()->name,
'from_email' => Auth::user()->email,
'subject' => $_subject,
'html' => $_body
),
'async' => true
);
$request = Httpful::post($url)->sendsJson()->body($data)->send();
if ( $request->body[0]->status == "queued" ) {
$success = true;
}
Again, huge thanks to Aiias for clearing some major confusion up for me!
I never worked with SOAP XML api before.
I read a couple of similar questions on SO but I can't get it to work.
Here's a simple request:
<soap12:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap12=”http://www.w3.org/2003/05/
soap-envelope”>
<soap12:Body>
<CheckDomainAvailability xmlns=”https://live.domainbox.net/”>
<AuthenticationParameters>
<Reseller>myreseller</Reseller>
<Username>myuser</Username>
<Password>mypassword</Password>
</AuthenticationParameters>
<CommandParameters>
<DomainName>checkadomain.co</DomainName>
<LaunchPhase>GA</LaunchPhase>
</CommandParameters>
</CheckDomainAvailability>
</soap12:Body>
</soap12:Envelope>
I've contacted them but they do not offer a PHP API.
I would like to use the SoapClient class built in PHP.
The question is:
How do I send the request and print the answer?
Looks like your WSDL is located at https://live.domainbox.net/?WSDL.
Here's an example using the native PHP SoapClient.
$client = new SoapClient('https://live.domainbox.net/?WSDL');
// populate the inputs....
$params = array(
'AuthenticationParameters' => array(
'Reseller' => '',
'Username' => '',
'Password' => ''
),
'CommandParameters' => array(
'DomainName' => '',
'LaunchPhase' => ''
)
);
$result = $client->CheckDomainAvailability($params);
print_r($result);
To get this working I needed to change the first line to get the right version of soap to 1.2.
Also a previous comment
$client = new SoapClient('https://live.domainbox.net/?WSDL', array('soap_version' => SOAP_1_2));
// populate the inputs....
$params = array(
'AuthenticationParameters' => array(
'Reseller' => '',
'Username' => '',
'Password' => ''
),
'CommandParameters' => array(
'DomainName' => '',
'LaunchPhase' => ''
)
);
$result = $client->CheckDomainAvailability($params);
print_r($result);