# 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 = "12345"
order1.AccountNumber = "67890"
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 = "
shipTo.City = "
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]
# Add this order to the batch
myBatchOrder.OrderArray.OrderType01Object
= [order1]
# To submit multiple orders, use:
#
myBatchOrder.Batch.OrderArray.OrderType01Object = [order1, order2,
order3]
# Send the request to the server
response
= client.service.SubmitBatchOrder(SessionID=sessionID, Batch=myBatchOrder)
# Read response
if response.ResultStatus.Error > 0:
print response.ResultStatus.ErrorStr
exit(0) # Check specific error
# Success
exit(0)