i wanna create soap request as below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.0">
<soapenv:Header/>
<soapenv:Body>
<ns:updateUser sequence="?">
<!--You have a CHOICE of the next 2 items at this level-->
<uuid>{74932749237942794729473927493829}</uuid>
<userid>?</userid>
<associatedGroups>
<!--Zero or more repetitions:-->
<userGroup>
<name>Standard CTI Enabled</name>
<!--Optional:-->
<userRoles>
<!--Zero or more repetitions:-->
<userRole>Standard CTI Enabled</userRole>
</userRoles>
</userGroup>
<userGroup>
<name>Standard CCM End Users</name>
<!--Optional:-->
<userRoles>
<!--Zero or more repetitions:-->
<userRole>Standard CCM End Users</userRole>
</userRoles>
</userGroup>
</associatedGroups>
</ns:updateUser>
</soapenv:Body>
</soapenv:Envelope>
I have this as my code so far:
$userId = "example#mydomain.com";
$retAccessWebex["UserUuid"] = "{74932749237942794729473927493829}"; //sample userUuid
$userGroup = array();
$userRoleCTI = array("Standard CTI Enabled");
$userGroup[] = array(
"name" => "Standard CTI Enabled",
"userRoles" => array(
"userRole" => $userRoleCTI,
)
);
$userRoleCCM = array("Standard CCM End Users");
$userGroup[] = array(
"name" => "Standard CCM End Users",
"userRoles" => array(
"userRole" => $userRoleCCM,
)
);
$param = array(
"uuid" => $retAccessWebex["UserUuid"],
"userid" => $userId,
"associatedGroups" => array(
array(
"userGroup" => $userGroup,
)
)
);
$mywsdl = "pathToSchemaWsdl/AXLAPI.wsdl";
$wsdl = "https://127.0.0.1:8443/axl/";
$client = new SoapClient($mywsdl,
array('trace' => true,
'exceptions' => true,
'location' => $wsdl,
'login' => 'administrator',
'password' => 'mtp455w0rd',
));
$response = $client->updateUser($param);
however, when executing, I get this error message:
Fatal error: Uncaught SoapFault exception: [Sender] SOAP-ERROR:
Encoding: object has no 'name' property
try to see what is in request
echo $client->__getLastRequestHeaders();
echo $client->__getLastRequest();
Related
I am trying to generate the params for below XML, but its not working. I doubt how I convert this to PHP array in $params, any help is appreciated
<soapenv:Header/>
<soapenv:Body>
<tem:GetServicesforPincode>
<!--Optional:-->
<tem:pinCode>695587</tem:pinCode>
<!--Optional:-->
<tem:profile>
<!--Optional:-->
<sapi:Api_type>S</sapi:Api_type>
<!--Optional:-->
<sapi:Customercode>099960</sapi:Customercode>
<!--Optional:-->
<sapi:LicenceKey>9b40edffc20ce2e6fc1462a30fc48181</sapi:LicenceKey>
<!--Optional:-->
<sapi:LoginID>BLR00132</sapi:LoginID>
<!--Optional:-->
</tem:profile>
</tem:GetServicesforPincode>
</soapenv:Body>
</soapenv:Envelope>
I tried like this:
$params = array(
'pinCode' => array (
"695587",
),
// 'pinCode' => '695587',
'Profile' => array(
'Api_type' => 'S',
'LicenceKey' => '9b40edffc20ce2e6fc1462a30fc48181',
'LoginID' => 'BLR00132',
'Version' => '1.3'
)
);
$wsdl = 'http://netconnect.bluedart.com/Ver1.8/Demo/ShippingAPI/Finder/ServiceFinderQuery.svc?wsdl';
$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
try {
$soap = new SoapClient($wsdl);
$data = $soap->GetServicesforPincode($params);
}
catch(Exception $e) {
die($e->getMessage());
}
print_r($data);
die;
I'm getting the following error:
Fatal error: Uncaught SoapFault exception: [s:Client] Service
operation Pickup_Cancel failed due to validation errors: Input is null
Here's my code:
$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl", array("trace" => 1, "exception" => 0));
$params = array(
"CodeStation" => `BEY`,
"PickupNumber" => `1`,
"Reason" => `test reason`,
"Password" => `sss`,
"ShipperAccount" => `acc`,
"UserName" => `acc`,
);
$client->Pickup_Cancel($params);
The awnser to the question you didn't ask is probably: replace the backticks (`) by singlequotes (')
-- Edit. That was not the problem.
Here is the case. SOAP can be a pain to get going. My experience is to use a good soap class or just non-wsdl mode. Read up on this in the docs: https://www.php.net/manual/en/soapclient.soapcall.php
So don't do this:
$return = $soapClient->functionName($data);
But this:
$return = $soapClient->__SoapCall('functionName', $data);
Also get a grip on what the server wants, load the WSDL url into a client like SoapUI https://www.soapui.org/ (its free). This lets you check if the SoapServer works and how you should approach it with your call.
In your case the WSDL states this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pos="http://schemas.datacontract.org/2004/07/PostaWebClient">
<soapenv:Header/>
<soapenv:Body>
<tem:Pickup_Cancel>
<!--Optional:-->
<tem:CLIENTINFO>
<!--Optional:-->
<pos:CodeStation>asd</pos:CodeStation>
<!--Optional:-->
<pos:Password>asd</pos:Password>
<!--Optional:-->
<pos:ShipperAccount>asd</pos:ShipperAccount>
<!--Optional:-->
<pos:UserName>asd</pos:UserName>
</tem:CLIENTINFO>
<!--Optional:-->
<tem:PickupNumber>asd</tem:PickupNumber>
<!--Optional:-->
<tem:Reason>asd</tem:Reason>
</tem:Pickup_Cancel>
</soapenv:Body>
</soapenv:Envelope>
Which translates to this PHP code:
$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl");
$params = [
'Pickup_Cancel' => [
'CLIENTINFO' => [
'Password' => 'sss',
'ShipperAccount' => 'acc',
'UserName' => 'acc',
'CodeStation' => '',
],
'PickupNumber' => '',
'Reason' => '',
],
];
$client->__SoapCall("Pickup_Cancel", $params);
See how the array matches the WSDL xml format?
This should also give you the feedback you need to proceed. If not, its probably time to get 'real' help :) Goodluck.
I have hml which works fine in SOAPUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"
xmlns:wssc="http://schemas.datacontract.org/2004/07/WSSC.V4.DMS.EKV.WssDocsService">
<soapenv:Header/>
<soapenv:Body>
<tem:CreateDocument>
<!--Optional:-->
<tem:parameters>
<!--Optional:-->
<!--Optional:-->
<wssc:DocType>01</wssc:DocType>
<!--Optional:-->
<!--Optional:-->
<!--Optional:-->
<wssc:FieldValues>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>value1</wssc:Name>
<!--Optional:-->
<wssc:Value>email#email.email</wssc:Value>
</wssc:BaseDocumentField>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>content</wssc:Name>
<!--Optional:-->
<wssc:Value>just text</wssc:Value>
</wssc:BaseDocumentField>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>name</wssc:Name>
<!--Optional:-->
<wssc:Value>number</wssc:Value>
</wssc:BaseDocumentField>
</wssc:FieldValues>
<wssc:UserMail>email#email.email</wssc:UserMail>
</tem:parameters>
</tem:CreateDocument>
</soapenv:Body>
</soapenv:Envelope>
I need to create an array to repeat its structure.
Now I have such an array, but it does not work to the full:
<?php
$params = array(
'parameters' => array(
'DocType' => '01',
'UserMail' => 'email#email.email',
'FieldValues' => array(
'BaseDocumentField' => array(
'name' => 'something',
'value' => 'something',
),
'BaseDocumentField' => array(
'name' => 'something',
'value' => 'something',
),
),
)
);
$client = new SoapClient("http://servicename?wsdl", array("trace" => 1, "exceptions" => 0, "login" => $login, "password" => $password));
$result = $client->CreateDocument($params);
try {
$request = $client->CreateDocument($params);
$last_request = $client->__getLastRequest();
} catch (SoapFault $exception) {
$last_request = $client->__getLastRequest();
}
var_dump($last_request);
?>
The function __getLastRequest produces the following result:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schemas.datacontract.org/2004/07/WSSC.V4.DMS.EKV.WssDocsService"
xmlns:ns2="http://tempuri.org/">
<SOAP-ENV:Body>
<ns2:CreateDocument>
<ns2:parameters>
<ns1:DocType>01</ns1:DocType>
<ns1:FieldValues>
<ns1:BaseDocumentField/>
</ns1:FieldValues>
<ns1:UserMail>email#email.email</ns1:UserMail>
</ns2:parameters>
</ns2:CreateDocument>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I do not understand how to properly construct an array so that the section is displayed correctly.
how can I do it?
If you're working with a complex WSDL, you should definitively use a WSDL to php generator such as the PackageGenerator project. It'll generate all the classes required to construct the request then to receive the response. Using a good IDE such as Eclipse or PhpStorm, you'll have the full auto-completion wich will ease you the request construction without having to wonder how to do it.
i've got this XML and it works in soapUi
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="xxx" xmlns:data="xxx">
<soapenv:Header/>
<soapenv:Body>
<web:FindArticles>
<web:request>
<data:culture_id>de-DE</data:culture_id>
<data:vehicle_search_parameters>
<data:address>
<!--Optional:-->
<data:countries>
<!--Zero or more repetitions:-->
<data:country_id>D</data:country_id>
</data:countries>
<!--Optional:-->
</data:address>
<data:dealer_id>XXX</data:dealer_id>
<data:show_dealer_vehicles>true</data:show_dealer_vehicles>
</data:vehicle_search_parameters>
</web:request>
</web:FindArticles>
</soapenv:Body>
</soapenv:Envelope>
But I can not fugure out how to call it via PHP. I'm trying something like this, but get errors...
<?php
$wsdl = 'XXX';
$options = array(
'login' => 'XXX',
'password' => 'XXX',
'trace'=>true
);
$params = array(
'culture_id' => 'de-DE',
'country_id' => 'D',
'dealer_id' => 'XXX',
'show_dealer_vehicles' => true
);
try {
$soap = new SoapClient($wsdl, $options);
$data = $soap->FindArticles($params);
}
catch(Exception $e) {
die($e->getMessage());
}
var_dump($data);
die;
It looks, that there is some kind of nested functions - how have I call it via PHP? I've tried smth like $soap->FindArticles('request', $params), but it still does not work
I am trying to make a SOAP call using PHP5. Here is the working schema:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cat="http://com.xxx.xxxx/management/catalog">
<soapenv:Header/>
<soapenv:Body>
<cat:ManageCustomProducts siteId="0">
<!--You have a CHOICE of the next 2 items at this level-->
<!--0 to 25 repetitions:-->
<cat:task id="?">
<cat:insertCustomProduct manufacturerId="?" manufacturerPartNo="?" categoryId="?" categoryType="default">
<cat:skus>
<!--Zero or more repetitions:-->
<cat:sku type="?" number="?"/>
</cat:skus>
<cat:resources>
<!--Zero or more repetitions:-->
<cat:resource type="?" status="?" url="?"/>
</cat:resources>
<cat:locales>
<!--1 or more repetitions:-->
<cat:locale language="?" country="?">
<cat:descriptions>
<!--Zero or more repetitions:-->
<cat:description type="?">e gero</cat:description>
</cat:descriptions>
<cat:marketingDescription>cum sonoras</cat:marketingDescription>
</cat:locale>
</cat:locales>
</cat:insertCustomProduct>
</cat:task>
</cat:ManageCustomProducts>
Here is my code to generate the SOAP XML...
$params=array(array(
'siteId' => '0',
'task' => array('id' => '1',
'insertCustomProduct' => array('manufacturerId' => '10000', 'manufacturerPartNo' => 'abc123', 'categoryId' => '20000', 'categoryType' => 'default',
'skus' => array('sku' => array('type' => 'MANUFACTURPARTNO', 'number' => 'abc123')),
'resources' => array('resource' => array('type' => '500', 'status' => 'Published', 'url' => 'http://content.xxx.com/img.jpg')),
'locales' => array('locale' => array('language' => 'en', 'country' => 'US',
'descriptions' => array('description' => array('_' =>'egeros', 'type' => '1')),
'marketingDescription' => array('_' => 'cum sonoras')
)
)
)
)
)
);
$result = $client->__soapCall("ManageCustomProducts",$params);
Here is the result...
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://com.xxx.xxx/management/catalog">
<SOAP-ENV:Body>
<ns1:ManageCustomProducts siteId="0">
<ns1:task id="1">
<ns1:insertCustomProduct manufacturerId="10000" manufacturerPartNo="abc123" categoryId="20000" categoryType="default">
<ns1:skus>
<ns1:sku type="MANUFACTURPARTNO" number="abc123"/>
</ns1:skus>
<ns1:resources>
<ns1:resource type="500" status="Published" url="http://content.xxx.com/img.jpg"/>
</ns1:resources>
<ns1:locales>
<ns1:locale language="en" country="US">
<ns1:descriptions>
<ns1:description type="1"/>
</ns1:descriptions>
<ns1:marketingDescription/>
</ns1:locale>
</ns1:locales>
</ns1:insertCustomProduct>
</ns1:task>
</ns1:ManageCustomProducts>
Even though I am using the suggested format of:
https://stackoverflow.com/a/1419407/3280665
array("foo" => array("_" => "cheese", "bar"=>"moo"));
This should produce following XML
<foo bar="moo">cheese</foo>`
It is not adding the element value for description or marketingDescription. What am I doing wrong?
Thanks!
Update: I can now add the nodes, but how do I add the Type attribute to the description node?
$desc=array();
$desc[]=new SoapVar("This is description 1",XSD_STRING,null,null,'ns1:description');
$desc[]=new SoapVar("This is description 2",XSD_STRING,null,null,'ns1:description');
$description = new SoapVar($desc, SOAP_ENC_OBJECT, null,null,'description');'