Skip to content

Instantly share code, notes, and snippets.

@clintmjohnson
Created May 18, 2015 17:40
Show Gist options
  • Save clintmjohnson/1b0aa952ca8c3cf5bc91 to your computer and use it in GitHub Desktop.
Save clintmjohnson/1b0aa952ca8c3cf5bc91 to your computer and use it in GitHub Desktop.
Channel Advisor / Python Get Orders API Script
from suds.client import Client
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# Specify Login Information
developer_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
password = 'xxxxxxxx'
account_guid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
# Specify URLs
wsdl_url = 'https://api.channeladvisor.com/ChannelAdvisorAPI/v6/OrderService.asmx?WSDL'
service_url = 'https://api.channeladvisor.com/ChannelAdvisorAPI/v6/OrderService.asmx'
# Initialize client.
client = Client(wsdl_url, location = service_url)
login = client.factory.create('APICredentials')
login.DeveloperKey = developer_key
login.Password = password
client.set_options(soapheaders=login)
# Instantiate our GetOrderList Object
getOrderList = client.factory.create('GetOrderList')
getOrderList.orderCriteria.OrderCreationFilterBeginTimeGMT = '2000-01-01T00:00:00'
getOrderList.orderCriteria.OrderCreationFilterEndTimeGMT = '2012-09-05T00:00:00'
getOrderList.orderCriteria.StatusUpdateFilterBeginTimeGMT = None
getOrderList.orderCriteria.StatusUpdateFilterEndTimeGMT = None
getOrderList.orderCriteria.JoinDateFiltersWithOr = None
getOrderList.orderCriteria.DetailLevel = 'High'
getOrderList.orderCriteria.ExportState = None
getOrderList.orderCriteria.OrderIDList = None
getOrderList.orderCriteria.ClientOrderIdentifierList = None
getOrderList.orderCriteria.OrderStateFilter = 'Active'
getOrderList.orderCriteria.PaymentStatusFilter = 'Cleared'
getOrderList.orderCriteria.CheckoutStatusFilter = 'Completed'
getOrderList.orderCriteria.ShippingStatusFilter = 'Unshipped'
getOrderList.orderCriteria.RefundStatusFilter = None
getOrderList.orderCriteria.DistributionCenterCode = None
getOrderList.orderCriteria.PageSize = 20
getOrderList.orderCriteria.PageNumberFilter = 1
continueRequests = True
while continueRequests is True:
print 'Page', getOrderList.orderCriteria.PageNumberFilter
result = client.service.GetOrderList(account_guid, getOrderList.orderCriteria)
ordersInResult = len(result.ResultData.OrderResponseItem)
print ' Orders In Page:', ordersInResult
for order in result.ResultData.OrderResponseItem:
print ' ', order.OrderID
if ordersInResult < 20:
continueRequests = False
else:
getOrderList.orderCriteria.PageNumberFilter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment