2016-05-15 47 views
0

我试图使用npm magento访问Magento SOAP API(v 1.9.2.4)。但是data总是null:今天尝试访问Node.js上的Magento SOAP API

var express = require('express'); 
var app = express(); 
var MagentoAPI = require('magento'); 
var magento = new MagentoAPI({ 
    host: 'localhost', 
    port: 8080, 
    path: '/magento/api/xmlrpc/', 
    login: 'mothership', 
    pass: 'bvZ0k0B02pTjujN' 
}); 

app.get('/', function (req, res) { 
    res.send('Customers: '); 
}); 

var magentoCallback = function(data) { 
    console.log('Got data: ' + data); 
    console.log(data); 
}; 

magento.login(function(err, sessId) { 
    if (err) { 
    console.log("Error accessing Magento"); 
    console.log(err); 
    console.log("Session ID: " + sessId); 
    return; 
    } 
    console.log("Connected to Magento"); 
    magento.core.info(magentoCallback); 
}); 

app.listen(3000, function() { 
    console.log('Racing on port 3000'); 
}); 

enter image description here

回答

0

,我是同样的问题,两小时后,我找到了解决方案。您需要将magentoCallback功能更改为:

var magentoCallback = function(err, response) { 
    if (err) { 
     return console.log(err); 
    } 

    console.log("Result: "); 
    console.log(response) 
}; 
相关问题