Author: Peter Driessen - [email protected]
This module let's you connect with a Magento 1.x webshop via SOAP V2 using the wsdl method. I still need to add a lot of methods, but I also explained how to create a custom method on your own.
Hope this helps you. Please let me know if you have any questions or comments.
Regards, Peter
Install via npm:
npm i --save magento-soap-promise
// Copyright 2017 Peter Driessen - [email protected]
// MIT License: https://opensource.org/licenses/MIT
'use strict';
const magentoClient = require('magento-soap-promise')
var mag = new magentoClient('https://www.yourdomain.com/api/v2_soap/?wsdl', 'Username', 'ApiKey');
mag.connect().then( sessionid => {
return mag.getOrder('900000744');
}).then((result) => {
console.log(JSON.stringify(result));
}).catch( error => {
console.log(error);
})
Get information about a single order
Get all pending sales orders
Get all processing orders
Add comment to an order, including new status and a comment description
Get shipment information
Add comment to a shipment
Create a shipment for an order, including a comment
Get product information
Get stock information about one or more products, argument is an array of product ID's
Update stock quantity for a single product
Basically all methods above make use of the custom method. You can create any method you want, based on the Magento documentation. http://devdocs.magento.com/guides/m1x/api/soap/introduction.html
-
Have a look at the SOAP V2 example
-
Copy the method behind $result = $proxy->, which is: catalogInventoryStockItemUpdate
-
Have a look at the wsdl file you used to connect and search for catalogInventoryStockItemUpdate
-
You will find this piece of code:
<message name="catalogInventoryStockItemUpdateRequest"> <part name="sessionId" type="xsd:string"/> <part name="product" type="xsd:string"/> <part name="data" type="typens:catalogInventoryStockItemUpdateEntity"/> </message>
-
SessionId is always send along our custom method, product needs a string and data is an argument as well. You have seen these arguments in the documentation at step 1 if it's correct.
-
You can construct the arguments object like this:
var args = { product: '2227', data: { qty: '46' } }
-
You can now use your custom method like in this full example:
'use strict'; const mag = require('./magentoClient2'); var mag = new magentoClient(); mag.connect('https://www.yourdomain.com/api/v2_soap/?wsdl', 'username', 'apiKey').then( sessionid => { // arguments var args = { product: '2227', data: { qty: '46' } } return mag.customCall('catalogInventoryStockItemUpdate', args); }).then((result) => { // output result in JSON console.log(JSON.stringify(result)); })