PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 31, 2022

[FIXED] How to authenticate with Pear SOAP_Client

 August 31, 2022     magento, pear, php, soap     No comments   

Issue

I am trying to login to my magento's web services from a server that does not have SoapClient enabled. So I figured I would install and use Pear's SOAP_Client but I can't figure out how to login.

With SoapClient I use:

$client = new SoapClient($WSDL);
$session = $client->login($user, $api_key);
$response = $client->call($session, $method, $arguments);

But I can't find an analog to the login method for SOAP_Client

I gather that I should be setting something in the $proxy_params of the constructor, but I can't find what the indexes should be.

$proxy_params = array();
$client = new SOAP_Client($wsdl, true, false, $proxy_params);
$client->call($method, $arguments)

Solution

So I figured this out, and there are a couple of factors here.

  1. There isn't a login function for SoapClient, the login I was calling is a call as defined in the WSDL

  2. The various magento API methods are not defined in the WSDL, you provide an argument resource method to method defined as call by the WSDL. This created a bit of confusion because using $client->call() seems to invoke call as defined by the SOAP_Client class, so I need to use $client->call('call') to invoke the SOAP method call

The final code ended up being:

$method = 'catalog_product.info';
$args = array($product_id);

$client = new SOAP_Client($wsdl, true);
$session_id = $client->call(
    'login',
    array(
        'username'=>$username,
        'apiKey'=> $pasword
    )
);
$ret = $client->call(
    'call',
    array(
        'sessionId'=>$session_id,
        'resourcePath'=>$method,
        'args'=>$args
    )
);


Answered By - ben
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing