Help needed in mapping Magento 1.x/PHP data structure into Python equivalent for suds
Parul M
parulm799 at gmail.com
Tue May 31 12:55:57 EDT 2016
Hello All,
I need assistance in calling Magento 1.x SOAP API's using Python suds
library.
How to map the *PHP data structure array(array(k1=>v1, k2=>v2,.....)) in
terms of python suds*???
The exposed SOAP API syntax for creating a new customer in magento:
ult = $client->call($session, 'customer.create', array(array('email' => '
customer-mail at example.org',
'firstname' =>
'Dough',
'lastname' => 'Deeks',
'password' => 'password',
'website_id' => 1,
'store_id' => 1)));
suds client instance:
>>> print client
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build:
R699-20100913
Service ( MagentoService ) tns="urn:Magento"
Prefixes (2)
ns0 = "http://schemas.xmlsoap.org/soap/encoding/"
ns1 = "urn:Magento"
Ports (1):
(Port)
Methods (8):
call(xs:string sessionId, xs:string resourcePath, xs:anyType
args, )
endSession(xs:string sessionId, )
globalFaults(xs:string sessionId, )
login(xs:string username, xs:string apiKey, )
multiCall(xs:string sessionId, FixedArray calls, xs:anyType
options, )
resourceFaults(xs:string resourceName, xs:string sessionId, )
resources(xs:string sessionId, )
startSession()
Types (49):
ns0:Array
ns0:ENTITIES
ns0:ENTITY
*My Efforts*:
>>> params={
... 'email':'customer123 at example.org',
... 'firstname':'Dough',
... 'lastname':'Deeks',
... 'password':'password',
... 'website_id':1,
... 'store_id':1,
... 'group_id':1
... }
>>> a1=client.factory.create("ns0:Array")
>>> a1["item"]=[{"key":key,"value":params[key]} for key in params]
>>> a1
(Array){
_arrayType = ""
_offset = ""
_id = ""
_href = ""
item[] =
{
value = 1
key = "group_id"
},
{
value = 1
key = "store_id"
},
{
value = "Dough"
key = "firstname"
},
{
value = "Deeks"
key = "lastname"
},
{
value = 1
key = "website_id"
},
{
value = "password"
key = "password"
},
{
value = "customer123 at example.org"
key = "email"
},
}
>>> a3=client.factory.create("ns0:Array")
>>> a3.array=a1
>>> a3
(Array){
_arrayType = ""
_offset = ""
_id = ""
_href = ""
array =
(Array){
_arrayType = ""
_offset = ""
_id = ""
_href = ""
item[] =
{
value = 1
key = "group_id"
},
{
value = 1
key = "store_id"
},
{
value = "Dough"
key = "firstname"
},
{
value = "Deeks"
key = "lastname"
},
{
value = 1
key = "website_id"
},
{
value = "password"
key = "password"
},
{
value = "customer123 at example.org"
key = "email"
},
}
}
>>> client.service.call(session,'customer.create',a3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\suds\client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "C:\Python27\lib\site-packages\suds\client.py", line 602, in invoke
result = self.send(soapenv)
File "C:\Python27\lib\site-packages\suds\client.py", line 643, in send
result = self.succeeded(binding, reply.message)
File "C:\Python27\lib\site-packages\suds\client.py", line 678, in
succeeded
reply, result = binding.get_reply(self.method, reply)
File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 151,
in get_reply
self.detect_fault(soapbody)
File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 182,
in detect_fault
raise WebFault(p, fault)
suds.WebFault: Server raised fault: 'Customer email is required'
The data provided, is obviously not in the correct format.
Any guidance would be much appreciated.
Thanks
More information about the Python-list
mailing list