Updated 2 years, 6 months and 10 days ago
Article on Custom routine creation in Talend for Magento
2. Create a Talend Job :
Go to Job Designs and select Create job to create a new Talend job and in give the name as MagentoConnection.
Load tWebServiceInput component from the palette and it will open a new window when we double click on it.
Configure Magento details in the component like below:
WSDL : http://magentohost/index.php/api/soap/?wsdl (replace your Magento host name with magentohost)
Method name: Make this value as empty [ double quotes (“”)]
Time out (second) : 60
Select Advanced settings and make sure to check the Advanced Use checkbox to generate client stub codes in Routines.
By default there is some routine available in the code section, remove it and click on WSDL2Java button so that component will generate wsdl files and shows a success message.
All the files will be stored under Codes/Routines/MagentoConnection directory.
After creating wsdl files for the Magento we need to create a routine to access Magento SOAP web services.
Go to code section in Talend and right – click on Routines and select Create routine and give name as Magento_Routine.
We need to create an API user in Magento to connect Magento web services. This API user is also related to a so-called API role. By default, there is neither API user nor API role, so we need to configure both.
First an API role needs to be added. Login to the Magento Admin Panel and navigate to
System > Web Services > SOAP/XML-RPC - Roles ( or Roles in old versions).
This page lists the current API roles. If there none listed yet, click on Add New Role.
Every role needs a name. This can be anything. Just make sure it is descriptive enough for yourself.
The second tab on the left (Role Resources) allows you to select which resources should be available for users with this role.
While you can select exactly which privileges are given, we recommend you select All unless you're willing to spend hours
Now that the role is created, you can add a user that makes use of this role.
The strange thing here is that the user fields here seem to indicate a person or individual, while in fact we're creating a
system account of some kind.
The fields First Name, Last Name and Email just need to be filled in with any value you like. Make sure the
User Name and Api Key are secure enough.
The second tab on the left is called User Role, and that's where you select the role earlier created.
Once the API user created successfully in admin panel then we need to make use those details in the Talend routine.
String url = “http://magentohost/index.php/api/soap/index/”;
Create a porttype object in the routine like below so that we will make use that object in entire routine.
Porttype is the Magento Api Model Server object that we already generated in wsdl files.
routines.Mage_Api_Model_Server_HandlerPortType porttype = new
Method : login(apiUser,apiKey)
apiUser : API Username
apiKey : API Key
Description : Start the API session, return the sessionID, and authorize the API user.
String SessionId = (String)porttype.login(“username”, “password”);
Method: call(SessionId, resourcePath, arrayArguments)
Sessionid : SessionID
Type :Product type
Set : ID of the product attribute set
Sku : Product SKU
productData : Array of catalogProductCreateEntity
storeView : Store view ID or code
String productId = (String) porttype.call(SessionId, “catalog_product.create”, arrlist); Create an Array List object to hold all the required arguments. java.util.ArrayList arrlist = new java.util.ArrayList(); Add all the attributes to the list object . arrlist.add(0, "simple");//product type arrlist.add(1, 10);//ID of the product attribute set arrlist.add(2, 999);//sku arrlist.add(prodDataMap); Here prodDataMap is a Map object and it contains all the product related entities.
If we want to update an existing Magento product then we can also update in a following way.
Method: call(SessionId, resourcePath, arrlist)
sessionid : SessionID
produt/productid : Product type
productData : Array of catalogProductCreateEntity
storeView : Store view ID or code(optional)
identifierType : Defines whether the product ID or SKU is passed in the ‘product’ parameter.
String productId = (String) porttype.call(SessionId, “catalog_product.update ”, arrlist); Create an array list object to hold all the required arguments to update a Magento product. java.util.ArrayList updatePrdList = new java.util.ArrayList(); updatePrdList.add(0,20);//Product id updatePrdList.add(1,arrlist);//productData
Go to Talend job MagentoConnection and edit the tWebServiceInput like below.
String url = “http://magentohost/index.php/api/soap/index/”; String apiUser =”test”; String apiPwd =”test123”; MagentoRoutine magento_routine = new MagentoRoutine(url); String sessionId = magento_routine.getSessionID(apiUser, apiPwd); System.out.println(sessionid);
Execute the Magento Connection job then we will get the Magento Sessionid.
Like the same way we can create product, category, customer, sales order, shipment and invoice.