Created
December 30, 2018 15:41
-
-
Save AurelienLavorel/f08b41a42dab73771ffa3a4e2be4ed1a to your computer and use it in GitHub Desktop.
Magento SOAP API call example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Contain the downloaded SOAP WSDL, you can copy paste it from /soap/?wsdl_list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| libxml_disable_entity_loader(false); | |
| $userData = array("username" => "xxx", "password" => "xxx"); | |
| $domain = "https://www.example.com"; | |
| $request = new SoapClient($domain . "/index.php/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2)); | |
| $token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken($userData); | |
| $opts = array( | |
| 'http'=>array( | |
| 'header' => 'Authorization: Bearer '.json_decode($token->result) | |
| ) | |
| ); | |
| $wsdlUrl = $domain . '/soap/default?wsdl&services=directoryCurrencyInformationAcquirerV1'; | |
| $wsdlUrl = $domain . '/soap/default?wsdl&services=salesOrderRepositoryV1'; | |
| $context = stream_context_create($opts); | |
| $soapClient = new SoapClient("s.xml", ['version' => SOAP_1_2, 'context' => $context, 'trace' => true]); | |
| $soapResponse = $soapClient->__getFunctions(); | |
| print_r($soapResponse); | |
| try { | |
| print_r($soapClient->salesOrderRepositoryV1GetList()); | |
| } catch (Exception $e) { | |
| echo($soapClient->__getLastResponse()); | |
| echo PHP_EOL; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment