#
Sample code to submit a batch order to DCL Web Services
# By Walter P. (DCL) - 12/27/2011
#
Python version: 2.7
#
#
Note:
#
Download suds from http://sourceforge.net/projects/python-suds/ (version 0.3.9
at this time)
# There are some other updated versions around (at least
0.4.1); the code works with both.
#
from sys import exit
from suds.client import Client
"""
Enable logging to see SOAP envelop
import
logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
"""
#
Create a SOAP client
client =
Client('https://www.efactory.dclcorp.com/WebServices/DCLWebService.asmx?WSDL')
# Set your credentials
sessionID = client.service.Login(strUser="username", strPwd="password")
#
Check if credentials are correct (if sessionID is
empty, wrong credentials)
if sessionID
== None:
print "Wrong credentials"
exit(0) # If sessionID is empty, wrong
credentials. Feel free to change exit code
#
Create a BatchType01Object instance
myBatchOrder = client.factory.create('BatchType01Object')
#
Set location ("FR" or "LA")
myBatchOrder.Location="FR"
#
Create a OrderType01Object instance (an order)
order1
= client.factory.create('OrderType01Object')
#
Order initialization (mandatory to define all "number" fields)
order1.OrderStatus
= "NormalOrder" # Or HoldOrder
or RushOrder
order1.OrderSubTotal
= 0
order1.ShippingAndHandling
= 0
order1.SalesTax
= 0
order1.InternationalHandling
= 0
order1.TotalDue
= 0
order1.AmountPaid
= 0
order1.NetDueCurrency
= 0
order1.BalanceDueUS
= 0
order1.InternationalDeclaredValue
= 0
order1.Insurance
= 0
order1.PackingListType
= 0
# Set some values
order1.OrderNumber
= "00123"
order1.AccountNumber
= "10501"
order1.FreightAccount
= "00500"
order1.ShippingCarrier
= "UPS"
order1.ShippingService
= "2ND DAY AIR"
# Create and set a ShipTo object
shipTo = client.factory.create('AddressType01Object')
shipTo.Company = "DCL"
shipTo.Attention = "Mr. Smith"
shipTo.Address1
= "123 Main Street"
shipTo.City = "Fremont"
shipTo.StateProvince =
"CA"
shipTo.PostalCode =
"94538"
shipTo.Country = "US"
order1.ShipTo
= shipTo
#
Create a DetailType01Object object (order item)
item1
= client.factory.create('DetailType01Object')
item1.ItemNumber
= "12345"
item1.Quantity
= 6
item1.Price
= 5.00
#
Create another order item
item2
= client.factory.create('DetailType01Object')
item2.ItemNumber
= "67890"
item2.Quantity
= 5
item2.Price
= 0
#
Attach these two items to the order
order1.DetailArray.DetailType01Object
= [item1, item2]
#
Create a OrderType01Object instance (an order)
order2
= client.factory.create('OrderType01Object')
#
Order initialization (mandatory to define all "number" fields)
order2.OrderStatus
= "NormalOrder" # Or HoldOrder
or RushOrder
order2.OrderSubTotal
= 0
order2.ShippingAndHandling
= 0
order2.SalesTax
= 0
order2.InternationalHandling
= 0
order2.TotalDue
= 0
order2.AmountPaid
= 0
order2.NetDueCurrency
= 0
order2.BalanceDueUS
= 0
order2.InternationalDeclaredValue
= 0
order2.Insurance
= 0
order2.PackingListType
= 0
# Set some values
order2.OrderNumber
= "00121"
order2.AccountNumber
= "10501"
order2.FreightAccount
= "00500"
order2.ShippingCarrier
= "UPS"
order2.ShippingService
= "2ND DAY AIR"
# Create and set a ShipTo object
shipTo = client.factory.create('AddressType01Object')
shipTo.Company = "DCL"
shipTo.Attention = "Mr. Albert"
shipTo.Address1
= "124 Main Street"
shipTo.City = "Fremont"
shipTo.StateProvince =
"CA"
shipTo.PostalCode =
"94538"
shipTo.Country = "US"
order2.ShipTo
= shipTo
#
Create a DetailType01Object object (order item)
item1
= client.factory.create('DetailType01Object')
item1.ItemNumber
= "12345"
item1.Quantity
= 1
item1.Price
= 5.00
#
Attach these two items to the order
order2.DetailArray.DetailType01Object
= [item1]
#
Create a OrderType01Object instance (an order)
order3
= client.factory.create('OrderType01Object')
#
Order initialization (mandatory to define all "number" fields)
order3.OrderStatus
= "NormalOrder" # Or HoldOrder
or RushOrder
order3.OrderSubTotal
= 0
order3.ShippingAndHandling
= 0
order3.SalesTax
= 0
order3.InternationalHandling
= 0
order3.TotalDue
= 0
order3.AmountPaid
= 0
order3.NetDueCurrency
= 0
order3.BalanceDueUS
= 0
order3.InternationalDeclaredValue
= 0
order3.Insurance
= 0
order3.PackingListType
= 0
# Set some values
order3.OrderNumber
= "00124"
order3.AccountNumber
= "10501"
order3.FreightAccount
= "00500"
order3.ShippingCarrier
= "UPS"
order3.ShippingService
= "2ND DAY AIR"
# Create and set a ShipTo object
shipTo = client.factory.create('AddressType01Object')
shipTo.Company = "DCL"
shipTo.Attention = "Mr. Manfred"
shipTo.Address1
= "124 Main Street"
shipTo.City = "Fremont"
shipTo.StateProvince =
"CA"
shipTo.PostalCode =
"94538"
shipTo.Country = "US"
order3.ShipTo
= shipTo
#
Create a DetailType01Object object (order item)
item1
= client.factory.create('DetailType01Object')
item1.ItemNumber
= "12345"
item1.Quantity
= 2
item1.Price
= 5.00
#
Attach these two items to the order
order3.DetailArray.DetailType01Object
= [item1]
#
Add this order to the batch
myBatchOrder.OrderArray.OrderType01Object
= [order1, order2, order3]
# To submit multiple orders, use:
#
myBatchOrder.Batch.OrderArray.OrderType01Object = [order1, order2,
order3]
#
Send the request to the server
response =
client.service.SubmitBatchOrder2(SessionID=sessionID, Batch=myBatchOrder)
#
Read general/common response
if response.ResultStatus.Error
> 0:
print response.ResultStatus.ErrorStr
exit(0) # Check specific error
#
Read order specific error (from an ordered list)
for orderStatus
in response.OrderStatusArray.ResultStatusObject:
if orderStatus.Error
> 0:
print orderStatus.ErrorStr
#
Success
exit(0)