magento api example

piaoling  2011-08-01 10:14:29

public function indexAction()
    {
        $apiUer = 'aland';
        $apiKey = '123456';
        $apiPath = 'catalog_product.list';
        $null = '';
        $catNeedle=0;
        $filters = array(
           'sku' => array('like'=>'nba'),
            );

        //$url = 'http://www.localhost.com/1900/index.php/api/?wsdl';
        //$client  = new SoapClient($url);
        //$session = $client->login($apiUer,$apiKey);
        //$result = $client->call($session,$apiPath);
        //var_dump($result);
        //$client->endSession($session);


        //$url = 'http://www.localhost.com/1900/index.php/api/xmlrpc';
        //$client  = new Zend_XmlRpc_Client($url);
        //$session = $client->call('login',array($apiUer,$apiKey));
        //$result = $client->call('call',array($session,$apiPath));
        //var_dump($result);
        //$session = $client->call('endSession',$session);

        /*
         * rest service
         * note:
         * before each call/multiCall function,you must set the sessionId.
         * the result are SimpleXMLElement Object.
         */
        $url = 'http://www.localhost.com/magento/index.php/api/rest';
        $client  = new Zend_Rest_Client($url);

        //get session id
        $session = $client->login($apiUer,$apiKey)->get()->response();
        //single call function
        $client->sessionId($session);
        $product = $client->call($session,$apiPath,array($filters))->get()->getIterator()->call;
        $customer= $client->call($session,'customer.list',$null)->get()->getIterator()->call;

        //multiCall function
        $client->sessionId($session);
        $multiCall = $client->multiCall($session,array(
            array($apiPath,$null),
            array($apiPath,array($filters)),
            ))->get()->getIterator()->multiCall;

        //var_dump($product,$customer,$multiCall);
        var_dump($customer);
//        echo $client->sayHello('Davey', 'Day')->get();
//        $newCustomer = array(
//            'firstname'  => 'First',
//            'lastname'   => 'Last',
//            'email'      => 'test3@example.com',
//            //for my version of magento (1.3.2.4) you SHOULD NOT
//            // hash the password, as in:
//            // 'password_hash' => 'password'
//            'password_hash'   => md5('password'),
//            // password hash can be either regular or salted md5:
//            // $hash = md5($password);
//            // $hash = md5($salt.$password).':'.$salt;
//            // both variants are valid
//            'store_id'   => 0,
//            'website_id' => 0
//        );
//        $customer= $client->call($session,'customer.create',array($newCustomer))->get()->getIterator()->call;
        //var_dump($customer);
        //var_dump($client->testit()->get()->getIterator());
        //$client->endSession($session);
    }

类别 :  magento(258)  |  浏览(4277)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: