1

I’m implementing a service in Python that interacts with Magento through SOAP v2. So far, I’m able to get the product list doing something like this:

import suds
from suds.client import Client
wsdl_file = 'http://server/api/v2_soap?wsdl=1'
user = 'user'
password = 'password'
client = Client(wsdl_file) # load the wsdl file
session = client.service.login(user, password) # login and create a session
client.service.catalogProductList(session)

However, I’m not able to create a product, as I don’t really know what data I should send and how to send it. I know the method I have to use is catalogProductCreate, but the PHP examples shown here don’t really help me.

Any input would be appreciated.

Thank you in advance.

davids
  • 6,259
  • 3
  • 29
  • 50

2 Answers2

1

You are there already. I think your issue is not able to translate the PHP array of arguments to be passed into Python Key Value pairs. If thats the case this will help you a bit. As well as need to set the attribute set using catalogProductAttributeSetList before you create the product

    attributeSets = client.service.catalogProductAttributeSetList(session)
    #print attributeSets
    # Not very sure how to get the current element from the attributeSets array. hope the below code will work 
    attributeSet = attributeSets[0]
    product_details = [{'name':'Your Product Name'},{'description':'Product description'},{'short_description':'Product short description'},{'weight':'10'},{    'status':'1'},{'url_key':'product-url-key'},{'url_path':'product-url-path'},{'visibility' :4},{'price':100},{'tax_class_id':1},{'categories': [2]},{'websites': [1]}]
    client.service.catalogProductCreate(session , 'simple', attributeSet.set_id, 'your_product_sku',product_details) 
davids
  • 6,259
  • 3
  • 29
  • 50
Haijerome
  • 1,540
  • 16
  • 21
  • Thank you very much, this is really helping me. However, I'm getting the following error after the service call: `suds.TypeNotFound: Type not found: 'productData'` – davids Mar 11 '13 at 11:18
  • You are welcome ;-) Not very sure to assist you further with this as i've not consumed any webservice using python... Fundamentally all you need to check is whats the request sent and whats the response you get...i hope the following threads help you further in this line http://stackoverflow.com/questions/7179888/suds-throwing-error-type-not-found-consuming-soap-service and http://stackoverflow.com/questions/8982669/suds-typenotfound-type-not-found-merchantcode – Haijerome Mar 11 '13 at 12:04
0
suds.TypeNotFound: Type not found: 'productData'

Because the productData format is not right. You may want to change from
product_details = [{'name':'Your Product Name'},{'description':'Product description'}, {'short_description':'Product short description'},{'weight':'10'},{ 'status':'1'},{'url_key':'product-url-key'},{'url_path':'product-url-path'},{'visibility' :4},{'price':100},{'tax_class_id':1},{'categories': [2]},{'websites': [1]}]

to
product_details = {'name':'Your Product Name','description':'Product description', 'short_description':'Product short description','weight':'10', 'status':'1','url_key':'product-url-key','url_path':'product-url-path','visibility' :4,'price':100,'tax_class_id':1,'categories': [2],'websites': [1]}

It works for me.

Jeremy
  • 104
  • 1
  • 3