-1

I am trying to develop an application in which I want to fetch magento orders and customers details.

I have written the following code to use SOAP API:

    <?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// require('vendor/zendframework/zend-server/src/Client.php');
// require('vendor/zendframework/zend-soap/src/Client.php');
// require('vendor/zendframework/zend-soap/src/Client/Common.php');

$wsdlurl = 'http://192.168.0.94/magento2/index.php/soap/default?wsdl&services=salesOrderRepositoryV1';

$token = 'rsgd11vmhelufr2a2jnk023bu0s3nk35';

$opts = ['http' => ['header' => "Authorization: Bearer ".$token]];
$context = stream_context_create($opts);
//$arguments =
$serviceArgs = array('searchCriteria'=> 
        array('filterGroups' => 
            array ('filters' =>
                array('field' =>'increment_id',
                      'value' => '000000002' , 
                      'condition_type' => 'eq')
                )
         )
);
$soapClient = new SoapClient($wsdlurl, ['version' => SOAP_1_2, 'context' => $context]);
// $soapClient->setSoapVersion(SOAP_1_2);
// $soapClient->setStreamContext($context);
$result = $soapClient->__getFunctions();
echo "<pre>"; print_r($result); 
?>

If, I uncomment the commented line then it work fines.But, I want to use this code outside Magento.

So I don't want to use uncommented code.

And by using above code I am getting the following output:

Array
(
    [0] => SalesOrderRepositoryV1GetResponse salesOrderRepositoryV1Get(SalesOrderRepositoryV1GetRequest $messageParameters)
    [1] => SalesOrderRepositoryV1GetListResponse salesOrderRepositoryV1GetList(SalesOrderRepositoryV1GetListRequest $messageParameters)
    [2] => SalesOrderRepositoryV1SaveResponse salesOrderRepositoryV1Save(SalesOrderRepositoryV1SaveRequest $messageParameters)
)

Can anyone help me to use this methods from list. I am not able to use this methods.If anyone have some solutions please let me know.

0

2 Answers 2

1

There is an exemple worked for me:

<?php


error_reporting(E_ALL);

ini_set('display_errors', 1);

require('vendor/zendframework/zend-server/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client/Common.php');

$wsdlurl = 'https://mpm.p7.dbm-dev.com/soap/default?wsdl&services=salesOrderRepositoryV1';


$request = new SoapClient('http://mpm.p7.dbm-dev.com/soap?wsdl=1&services=integrationAdminTokenServiceV1', array("soap_version" => SOAP_1_2));
$token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username" => 'Shippingbo', "password" => "4FJ}Gv,("));


$opts = [
    'http' =>
        [
            'header' => "Authorization: Bearer ".$token->result
        ],
    'ssl' => [
        'allow_self_signed' => true ,
        'verify_peer' => false,
        'verify_peer_name' => false]
];

$context = stream_context_create($opts); //$arguments = $serviceArgs =
$serviceArgs = array('searchCriteria' =>
    array('filterGroups' =>
        array('filters' =>
            array('field' => 'increment_id',
                'value' => '000060040',
                'condition_type' => 'eq')
        )
    ));
$soapClient = new \Zend\Soap\Client($wsdlurl);
$soapClient->setSoapVersion(SOAP_1_2);
$soapClient->setStreamContext($context);
$result = $soapClient->salesOrderRepositoryV1GetList($serviceArgs);

echo '<pre>';
print_r($result);
0

I can see that multiple lines are commented out and it is quite difficult to understand which lines particulary you question. Here are my thoughts related to the last two commented lines:

// $soapClient->setSoapVersion(SOAP_1_2);
// $soapClient->setStreamContext($context);

I'm using Magento CE 2.2.0. When creating the new SoapClient object, do not use key "context". It gives in response "Unauthorized" even if username, password and token is valid. Instead use "stream_context" as key and store the context object with token in it's value.

At least, this was my situations and maybe this helps in your case as well.

Otherwise, please specify the lines and exact problem because I can see that __getFunctions endpoint works properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.