Orders¶
Listing all Orders¶
A GET
request to /api/orders/
is used to list all orders.
Using count
and offset
restricts the number of returned orders.
Parameter | Description |
---|---|
count | Limit the number of results. This can improve performance. |
offset | The start position of results, used for paging result sets.
Can be used with count parameter. |
"""
List all orders using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
orders_url = 'https://%s:%d/api/orders/?count=10&offset=0' % (ONSITE_HOST, ONSITE_PORT)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# Setup a session for the http request.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
session.stream = True
# Send the request to list all orders.
get_response = session.get(orders_url)
assert get_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Get the response and print it.
response_xml = minidom.parseString(get_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<orders total_count="2">
<order full_render="false" id="71" uri="https://localhost:9630/api/orders/71/">
<datetime_created>2017-07-12T09:11:07.559621</datetime_created>
<order_id>O-71</order_id>
<order_customer>
<customer id="13" uri="https://localhost:9630/api/customers/13/">
<merged_to>
<customer/>
</merged_to>
</customer>
<mainname>Wendy Marvell-09:10AM</mainname>
<mainphone>555-666-7777</mainphone>
<contact_info>555-666-7777
555-666-7777
[email protected]</contact_info>
</order_customer>
<totals>
<total>99.99</total>
</totals>
</order>
<order full_render="false" id="72" uri="https://localhost:9630/api/orders/72/">
<datetime_created>2017-07-17T11:49:04.368959</datetime_created>
<order_id>O-72</order_id>
<order_customer>
<customer/>
<mainname>June Masters</mainname>
<mainphone/>
<contact_info/>
</order_customer>
<totals>
<total>50.00</total>
</totals>
</order>
</orders>
Warning
This request can time-out if there are too many orders to return. Use limit and offset parameters to mitigate this.
Note
It is recommended to search orders rather than to list them all. See Searching Orders.
Getting an Order¶
A GET
request to /api/orders/{order id}/
is used to get a single order.
"""
Get an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_id = 72
order_url = 'https://%s:%d/api/orders/%d/' % (ONSITE_HOST, ONSITE_PORT, order_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# Setup a session for the http request.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
session.stream = True
# Send the request to get an order.
get_response = session.get(order_url)
assert get_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Get the response and print it.
response_xml = minidom.parseString(get_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<order full_render="true" id="72" uri="https://localhost:9630/api/orders/72/">
<document_id>72</document_id>
<date_created>2017-07-17</date_created>
<datetime_created>2017-07-17T11:49:04.368959</datetime_created>
<date_modified>2017-07-17</date_modified>
<datetime_modified>2017-07-17T11:49:14.470913</datetime_modified>
<order_id>O-72</order_id>
<order_customer>
<customer/>
<mainname>d</mainname>
<mainphone/>
<phone_email/>
<contact/>
<contact_info/>
<discount>0.000</discount>
<pricing_level>0</pricing_level>
<terms_tax/>
<zip/>
<po/>
</order_customer>
<margin>100.000</margin>
<print_options>
<localizable_language full_render="true" id="0" uri="https://localhost:9630/api/setup/localizable_languages/0/">
<name>English</name>
<list_order>0</list_order>
</localizable_language>
<images/>
<discounts>false</discounts>
</print_options>
<primary_user>
<user id="2" uri="https://localhost:9630/api/users/2/"/>
</primary_user>
<secondary_user>
<user/>
</secondary_user>
<printed_notes/>
<internal_notes/>
<shipping_method id="0" uri="https://localhost:9630/api/setup/shipping_methods/0/">
<name>None</name>
</shipping_method>
<currency full_render="true" id="1" uri="https://localhost:9630/api/setup/currencies/1/">
<name>US</name>
<rate>1.000000</rate>
<symbol>$</symbol>
</currency>
<terms/>
<due>2017-07-17</due>
<import_id/>
<status>Invoiced</status>
<tax_code id="0" uri="https://localhost:9630/api/tax_codes/0/"/>
<taxes inclusive="false">
<tax_exempt>
<tax id="1" rate="7.00">false</tax>
<tax id="2">false</tax>
<tax id="3">false</tax>
<tax id="4">false</tax>
<tax id="5">false</tax>
</tax_exempt>
</taxes>
<pricing_level/>
<c_discount_percentage>0.000</c_discount_percentage>
<payments/>
<billing/>
<shipping/>
<lineitems>
<lineitem full_render="false" id="81" uri="https://localhost:9630/api/orders/72/lineitems/81/">
<quantity>1.000</quantity>
<sell_price>50.000</sell_price>
<sells>
<sell>50.000</sell>
<base>50.000</base>
<total>50.00</total>
<sell_quantity_discount>50.000</sell_quantity_discount>
<sell_tax_inclusive>50.000</sell_tax_inclusive>
<sell_tax_inclusive_total>50.00</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>50.000</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="3" uri="https://localhost:9630/api/products/3/"/>
<code>GIFT-CARD</code>
<description/>
</lineitem_product>
</lineitem>
</lineitems>
<flags>
<drop_shipment>false</drop_shipment>
</flags>
<totals>
<subtotal>50.00</subtotal>
<tax>0.00</tax>
<credit/>
<total>50.00</total>
</totals>
<web_order_number/>
<order_type>Customer</order_type>
</order>
Creating an Order¶
A POST
request to /api/orders/
is used to create an order.
With a Walk-in Customer¶
Orders can be created with walk-in customers, that is to say, there’s no customer entry made for them.
"""
Create an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
orders_url = 'https://%s:%d/api/orders/' % (ONSITE_HOST, ONSITE_PORT)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the order that will be created.
order_xml = """
<order>
<order_customer>
<mainname>Jane Doe</mainname>
<phone>555-123-4567</phone>
</order_customer>
</order>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Send the request to create the order.
post_response = session.post(orders_url, data=order_xml)
assert post_response.status_code == 201
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Get the response and print it.
response_xml = minidom.parseString(post_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<order full_render="true" id="73" uri="https://localhost:9630/api/orders/73/">
<document_id>73</document_id>
<date_created>2017-07-20</date_created>
<datetime_created>2017-07-20T14:40:33.989343</datetime_created>
<date_modified>2017-07-20</date_modified>
<datetime_modified>2017-07-20T14:40:34.031188</datetime_modified>
<order_id>O-73</order_id>
<order_customer>
<customer/>
<mainname>Jane Doe</mainname>
<mainphone/>
<phone_email/>
<contact/>
<contact_info/>
<discount>0.0</discount>
<pricing_level>0</pricing_level>
<terms_tax/>
<zip/>
<po/>
</order_customer>
<margin>0.00</margin>
<print_options>
<localizable_language full_render="true" id="0" uri="https://localhost:9630/api/setup/localizable_languages/0/">
<name>English</name>
<list_order>0</list_order>
</localizable_language>
<images>0</images>
<discounts>false</discounts>
</print_options>
<primary_user>
<user id="2" uri="https://localhost:9630/api/users/2/"/>
</primary_user>
<secondary_user>
<user/>
</secondary_user>
<printed_notes/>
<internal_notes/>
<shipping_method/>
<currency full_render="true" id="1" uri="https://localhost:9630/api/setup/currencies/1/">
<name>US</name>
<rate>1.000000</rate>
<symbol>$</symbol>
</currency>
<terms/>
<due/>
<import_id/>
<status>None</status>
<tax_code id="0" uri="https://localhost:9630/api/tax_codes/0/"/>
<taxes inclusive="false">
<tax_exempt>
<tax id="1" rate="7.00" total="0.00">false</tax>
<tax id="2" rate="0.00" total="0.00">false</tax>
<tax id="3" rate="0.00" total="0.00">false</tax>
<tax id="4" rate="0.00" total="0.00">false</tax>
<tax id="5" rate="0.00" total="0.00">false</tax>
</tax_exempt>
</taxes>
<pricing_level/>
<c_discount_percentage>0.0</c_discount_percentage>
<payments/>
<billing/>
<shipping/>
<lineitems/>
<flags>
<drop_shipment>false</drop_shipment>
</flags>
<totals>
<subtotal>0.00</subtotal>
<tax>0.00</tax>
<credit>0.00</credit>
<total>0.00</total>
</totals>
<web_order_number/>
<order_type>Customer</order_type>
</order>
With an Existing Customer¶
Orders can be created with existing customers. How to create customers is explained in Customers.
"""
Create an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
orders_url = 'https://%s:%d/api/orders/' % (ONSITE_HOST, ONSITE_PORT)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the order that will be created.
order_xml = """
<order>
<order_customer>
<customer id="15"/>
</order_customer>
</order>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Send the request to create the order.
post_response = session.post(orders_url, data=order_xml)
assert post_response.status_code == 201
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Get the response and print it.
response_xml = minidom.parseString(post_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<order full_render="true" id="74" uri="https://localhost:9630/api/orders/74/">
<document_id>74</document_id>
<date_created>2017-07-20</date_created>
<datetime_created>2017-07-20T14:43:40.416959</datetime_created>
<date_modified>2017-07-20</date_modified>
<datetime_modified>2017-07-20T14:43:40.457968</datetime_modified>
<order_id>O-74</order_id>
<order_customer>
<customer id="15" uri="https://localhost:9630/api/customers/15/">
<merged_to>
<customer/>
</merged_to>
</customer>
<mainname>Jane Smith</mainname>
<mainphone>613-555-5555</mainphone>
<phone_email/>
<contact>Jane Smith</contact>
<contact_info>613-555-5555
613-555-5555
[email protected]</contact_info>
<discount>0.0</discount>
<pricing_level>0</pricing_level>
<terms_tax/>
<zip/>
<po/>
</order_customer>
<margin>0.00</margin>
<print_options>
<localizable_language full_render="true" id="0" uri="https://localhost:9630/api/setup/localizable_languages/0/">
<name>English</name>
<list_order>0</list_order>
</localizable_language>
<images>0</images>
<discounts>false</discounts>
</print_options>
<primary_user>
<user id="2" uri="https://localhost:9630/api/users/2/"/>
</primary_user>
<secondary_user>
<user/>
</secondary_user>
<printed_notes/>
<internal_notes/>
<shipping_method/>
<currency full_render="true" id="1" uri="https://localhost:9630/api/setup/currencies/1/">
<name>US</name>
<rate>1.000000</rate>
<symbol>$</symbol>
</currency>
<terms/>
<due/>
<import_id/>
<status>None</status>
<tax_code id="0" uri="https://localhost:9630/api/tax_codes/0/"/>
<taxes inclusive="false">
<tax_exempt>
<tax id="1" rate="7.00" total="0.00">false</tax>
<tax id="2" rate="0.00" total="0.00">false</tax>
<tax id="3" rate="0.00" total="0.00">false</tax>
<tax id="4" rate="0.00" total="0.00">false</tax>
<tax id="5" rate="0.00" total="0.00">false</tax>
</tax_exempt>
</taxes>
<pricing_level/>
<c_discount_percentage>0.0</c_discount_percentage>
<payments/>
<billing/>
<shipping/>
<lineitems/>
<flags>
<drop_shipment>false</drop_shipment>
</flags>
<totals>
<subtotal>0.00</subtotal>
<tax>0.00</tax>
<credit>0.00</credit>
<total>0.00</total>
</totals>
<web_order_number/>
<order_type>Customer</order_type>
</order>
Adding Products to an Order¶
A POST
request to /api/orders/{id}/lineitems/
is used to add a product to an order.
This must be preceded by a LOCK
request to the same endpoint, and followed by an UNLOCK
request.
See Locking & Unlocking Resources.
"""
Add products to an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_id = 67
order_url = 'https://%s:%d/api/orders/%d/' % (ONSITE_HOST, ONSITE_PORT, order_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the product being added to the order.
line_items_xml = """
<lineitem>
<quantity>1</quantity>
<lineitem_product>
<product id="3"/>
</lineitem_product>
</lineitem>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Lock the order before making the change.
lock_response = session.request('LOCK', order_url)
assert lock_response.status_code == 200
# Send the request to update the order.
post_response = session.post(order_url + 'lineitems/', data=line_items_xml)
assert post_response.status_code == 201
# Unlock the order after the change is complete.
unlock_response = session.request('UNLOCK', order_url)
assert unlock_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Print the revised product.
response_xml = minidom.parseString(post_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<response>
<lineitem full_render="true" id="82" uri="https://localhost:9630/api/orders/67/lineitems/82/">
<cost edited="false" total="0.00">0</cost>
<discount/>
<pricing_level/>
<profit_margin minimum="0.000"/>
<quantity>1</quantity>
<quantity_discount>false</quantity_discount>
<sell_price>50.00</sell_price>
<sells>
<sell>50.00</sell>
<base>50.000</base>
<total>50.00</total>
<sell_quantity_discount>50.00</sell_quantity_discount>
<sell_tax_inclusive>50.000</sell_tax_inclusive>
<sell_tax_inclusive_total>50.00</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>50.00</sell_tax_inclusive_discounted>
</sells>
<editable>true</editable>
<manual>false</manual>
<lineitem_product>
<product full_render="true" id="3" uri="https://localhost:9630/api/products/3/">
<class id="9" uri="https://localhost:9630/api/setup/classes/9/"/>
<currency id="1" uri="https://localhost:9630/api/setup/currencies/1/"/>
<code>CORGIFT</code>
<costs>
<cost/>
<average>0.000</average>
<raw/>
</costs>
<supplier_costs/>
<flags>
<current>true</current>
<editable>true</editable>
<gift_card>true</gift_card>
<inventoried>false</inventoried>
<new_cost>false</new_cost>
<new_import>false</new_import>
<new_update>false</new_update>
<no_live_rules>false</no_live_rules>
<no_profit>false</no_profit>
<serialized>false</serialized>
<web>false</web>
<editable_sell>false</editable_sell>
<master_model>false</master_model>
</flags>
<sell_price>50.000</sell_price>
<pricing_levels/>
<created>2017-07-07T13:00:18.501813</created>
<modified>2017-07-07T13:03:35.764628</modified>
<description/>
<long_web_description/>
<family/>
<gl_product>
<asset/>
<cogs_expense/>
<income/>
<payable_expense/>
</gl_product>
<product_id>P-1002</product_id>
<import_id/>
<inventory>
<available>-11.000</available>
<reserved>0.000</reserved>
<coming_for_stock>0</coming_for_stock>
<coming_for_customer>0</coming_for_customer>
<warehouses>0.000</warehouses>
<in_transit>0.000</in_transit>
<total>-11.000</total>
</inventory>
<margin/>
<minimum_margin>0.000</minimum_margin>
<notes/>
<product_info>
<color/>
<height>0.000</height>
<length>0.000</length>
<size/>
<weight>0.000</weight>
<width>0.000</width>
</product_info>
<reorder>
<amount>0.000</amount>
<calc>0.000</calc>
<point>0.000</point>
<type>0</type>
</reorder>
<sells>
<sell>50.000</sell>
<sell_tax_inclusive/>
<sell_web/>
</sells>
<supplier id="1" uri="https://localhost:9630/api/suppliers/1/"/>
<supplier_code/>
<upc/>
<web>
<inventory/>
</web>
<keywords>
<keyword/>
<keyword/>
<keyword/>
</keywords>
<multi_store_label>3</multi_store_label>
<multi_store_master_label/>
<categories>
<pos/>
<web/>
</categories>
<related_products/>
<serial_numbers/>
<product_photos/>
<tax_exemption id="38" uri="https://localhost:9630/api/setup/tax_exemptions/38/">
<name>No Tax</name>
<taxes>
<tax id="1">
<exempt>true</exempt>
</tax>
<tax id="2">
<exempt>false</exempt>
</tax>
<tax id="3">
<exempt>false</exempt>
</tax>
<tax id="4">
<exempt>false</exempt>
</tax>
<tax id="5">
<exempt>false</exempt>
</tax>
</taxes>
<active>true</active>
</tax_exemption>
<master_product/>
</product>
<code>CORGIFT</code>
<family/>
<description/>
<class_name/>
<current>true</current>
<editable>true</editable>
<editable_sell>false</editable_sell>
<gift_card>true</gift_card>
<inventoried>false</inventoried>
<no_profit>false</no_profit>
<serialized>false</serialized>
</lineitem_product>
<tax_exemption id="38" uri="https://localhost:9630/api/setup/tax_exemptions/38/"/>
<taxes>
<tax id="1">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="2">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="3">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="4">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="5">
<exempt>true</exempt>
<total>0.00</total>
</tax>
</taxes>
<status>Requested</status>
<quantity_received>0.00</quantity_received>
</lineitem>
<order full_render="true" id="67" uri="https://localhost:9630/api/orders/67/">
<document_id>67</document_id>
<date_created>2017-07-12</date_created>
<datetime_created>2017-07-12T09:10:20.452956</datetime_created>
<date_modified>2017-07-20</date_modified>
<datetime_modified>2017-07-20T15:17:13.626943</datetime_modified>
<order_id>O-67</order_id>
<order_customer>
<customer/>
<mainname>Gray Fullbuster-09:10AM</mainname>
<mainphone>333.444.5555</mainphone>
<phone_email/>
<contact/>
<contact_info/>
<discount>0.000</discount>
<pricing_level>0</pricing_level>
<terms_tax/>
<zip/>
<po/>
</order_customer>
<margin>96.99</margin>
<print_options>
<localizable_language full_render="true" id="0" uri="https://localhost:9630/api/setup/localizable_languages/0/">
<name>English</name>
<list_order>0</list_order>
</localizable_language>
<images>0</images>
<discounts>false</discounts>
</print_options>
<primary_user>
<user id="2" uri="https://localhost:9630/api/users/2/"/>
</primary_user>
<secondary_user>
<user/>
</secondary_user>
<printed_notes/>
<internal_notes/>
<shipping_method/>
<currency full_render="true" id="1" uri="https://localhost:9630/api/setup/currencies/1/">
<name>US</name>
<rate>1.000000</rate>
<symbol>$</symbol>
</currency>
<terms/>
<due>2017-07-12</due>
<import_id/>
<status>Requested</status>
<tax_code id="0" uri="https://localhost:9630/api/tax_codes/0/"/>
<taxes inclusive="false">
<tax_exempt>
<tax id="1" rate="7.00" total="2.98">false</tax>
<tax id="2" rate="0.00" total="0.00">false</tax>
<tax id="3" rate="0.00" total="0.00">false</tax>
<tax id="4" rate="0.00" total="0.00">false</tax>
<tax id="5" rate="0.00" total="0.00">false</tax>
</tax_exempt>
</taxes>
<pricing_level/>
<c_discount_percentage>0.000</c_discount_percentage>
<payments/>
<billing/>
<shipping/>
<lineitems>
<lineitem full_render="false" id="74" uri="https://localhost:9630/api/orders/67/lineitems/74/">
<quantity>1.000</quantity>
<sell_price>42.500</sell_price>
<sells>
<sell>42.500</sell>
<base>42.500</base>
<total>42.50</total>
<sell_quantity_discount>42.500</sell_quantity_discount>
<sell_tax_inclusive>45.475</sell_tax_inclusive>
<sell_tax_inclusive_total>45.48</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>45.48</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="42" uri="https://localhost:9630/api/products/42/"/>
<code>333-002-09:10AM</code>
<description>Celestial Whip-09:10AM</description>
</lineitem_product>
</lineitem>
<lineitem full_render="false" id="82" uri="https://localhost:9630/api/orders/67/lineitems/82/">
<quantity>1</quantity>
<sell_price>50.00</sell_price>
<sells>
<sell>50.00</sell>
<base>50.000</base>
<total>50.00</total>
<sell_quantity_discount>50.00</sell_quantity_discount>
<sell_tax_inclusive>50.000</sell_tax_inclusive>
<sell_tax_inclusive_total>50.00</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>50.00</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="3" uri="https://localhost:9630/api/products/3/"/>
<code>CORGIFT</code>
<description/>
</lineitem_product>
</lineitem>
</lineitems>
<flags>
<drop_shipment>false</drop_shipment>
</flags>
<totals>
<subtotal>92.50</subtotal>
<tax>2.98</tax>
<credit>0.00</credit>
<total>95.48</total>
</totals>
<web_order_number/>
<order_type>Customer</order_type>
</order>
</response>
Updating an Order¶
A PUT
request to /api/orders/{id}/
is used to update an order.
This must be preceded by a LOCK
request to the same endpoint, and followed by an UNLOCK
request.
See Locking & Unlocking Resources.
"""
Update an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
product_id = 62
order_url = 'https://%s:%d/api/orders/%d/' % (ONSITE_HOST, ONSITE_PORT, product_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the updated information for the order.
order_xml = """
<order>
<internal_notes>This customer requested that the items be gift-wrapped.</internal_notes>
</order>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Lock the order before making the change.
lock_response = session.request('LOCK', order_url)
assert lock_response.status_code == 200
# Send the request to update the order.
put_response = session.put(order_url, data=order_xml)
assert put_response.status_code == 200
# Unlock the order after the change is complete.
unlock_response = session.request('UNLOCK', order_url)
assert unlock_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Print the revised order.
response_xml = minidom.parseString(put_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<order full_render="true" id="62" uri="https://localhost:9630/api/orders/62/">
<document_id>62</document_id>
<date_created>2017-07-12</date_created>
<datetime_created>2017-07-12T09:10:15.229206</datetime_created>
<date_modified>2017-07-20</date_modified>
<datetime_modified>2017-07-20T16:04:20.614300</datetime_modified>
<order_id>O-62</order_id>
<order_customer>
<customer/>
<mainname>Natsu Dragneel-09:10AM</mainname>
<mainphone/>
<phone_email/>
<contact/>
<contact_info/>
<discount>0.000</discount>
<pricing_level>0</pricing_level>
<terms_tax/>
<zip/>
<po/>
</order_customer>
<margin>100.00</margin>
<print_options>
<localizable_language full_render="true" id="0" uri="https://localhost:9630/api/setup/localizable_languages/0/">
<name>English</name>
<list_order>0</list_order>
</localizable_language>
<images>0</images>
<discounts>false</discounts>
</print_options>
<primary_user>
<user id="2" uri="https://localhost:9630/api/users/2/"/>
</primary_user>
<secondary_user>
<user/>
</secondary_user>
<printed_notes/>
<internal_notes>This customer requested that the items be gift-wrapped.</internal_notes>
<shipping_method/>
<currency full_render="true" id="1" uri="https://localhost:9630/api/setup/currencies/1/">
<name>US</name>
<rate>1.000000</rate>
<symbol>$</symbol>
</currency>
<terms/>
<due>2017-07-12</due>
<import_id/>
<status>Requested</status>
<tax_code id="0" uri="https://localhost:9630/api/tax_codes/0/"/>
<taxes inclusive="false">
<tax_exempt>
<tax id="1" rate="7.00" total="2.80">false</tax>
<tax id="2" rate="0.00" total="0.00">false</tax>
<tax id="3" rate="0.00" total="0.00">false</tax>
<tax id="4" rate="0.00" total="0.00">false</tax>
<tax id="5" rate="0.00" total="0.00">false</tax>
</tax_exempt>
</taxes>
<pricing_level/>
<c_discount_percentage>0.000</c_discount_percentage>
<payments/>
<billing/>
<shipping/>
<lineitems>
<lineitem full_render="false" id="69" uri="https://localhost:9630/api/orders/62/lineitems/69/">
<quantity>2.000</quantity>
<sell_price>20.000</sell_price>
<sells>
<sell>20.000</sell>
<base>20.000</base>
<total>40.00</total>
<sell_quantity_discount>20.000</sell_quantity_discount>
<sell_tax_inclusive>21.400</sell_tax_inclusive>
<sell_tax_inclusive_total>42.80</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>21.40</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="44" uri="https://localhost:9630/api/products/44/"/>
<code>333-004-09:10AM</code>
<description>Juvia's Hat-09:10AM</description>
</lineitem_product>
</lineitem>
</lineitems>
<flags>
<drop_shipment>false</drop_shipment>
</flags>
<totals>
<subtotal>40.00</subtotal>
<tax>2.80</tax>
<credit>0.00</credit>
<total>42.80</total>
</totals>
<web_order_number/>
<order_type>Customer</order_type>
</order>
List Payments on an Order¶
A GET
request to /api/orders/{id}/payments/
is used to list payments on an order.
"""
Get payments on an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_id = 63
order_payments_url = 'https://%s:%d/api/orders/%d/payments/' % (ONSITE_HOST, ONSITE_PORT, order_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# Setup a session for the http request.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
session.stream = True
# Send the request to list all payments.
get_response = session.get(order_payments_url)
assert get_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Get the response and print it.
response_xml = minidom.parseString(get_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<payments>
<payment id="7" uri="https://localhost:9630/api/orders/63/payments/7/"/>
<payment id="16" uri="https://localhost:9630/api/orders/63/payments/16/"/>
</payments>
Get a Payment on an Order¶
A GET
request to /api/orders/{order id}/payments/{payment id}/
is used to get a payment on an order.
"""
Get a payment on an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_id = 63
payment_id = 16
order_payment_url = 'https://%s:%d/api/orders/%d/payments/%d/' % (ONSITE_HOST, ONSITE_PORT, order_id, payment_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# Setup a session for the http request.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
session.stream = True
# Send the request to get an order payment.
get_response = session.get(order_payment_url)
assert get_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Get the response and print it.
response_xml = minidom.parseString(get_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<payment id="16" uri="https://localhost:9630/api/orders/63/payments/16/">
<type>Web Payment</type>
<payment_method>VISA</payment_method>
<datetime_created>2017-07-20T15:50:25.714655</datetime_created>
<datetime_modified>2017-07-20T15:50:25.714053</datetime_modified>
<exported/>
<posted/>
<flags>
<exported>false</exported>
<posted>false</posted>
<voided>false</voided>
</flags>
<number/>
<source id="O-63">Natsu Dragneel-09:10AM</source>
<amount>50.00</amount>
<tendered/>
<authcode/>
<avs_result/>
<till/>
<signature_photo/>
</payment>
Making a Payment on an Order¶
A POST
request to /api/orders/{id}/payments/
is used to add a payment to an order.
This must be preceded by a LOCK
request to the same endpoint, and followed by an UNLOCK
request.
See Locking & Unlocking Resources.
"""
Add a payment to an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_id = 63
order_url = 'https://%s:%d/api/orders/%d/' % (ONSITE_HOST, ONSITE_PORT, order_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the payment being added to the order.
payment_xml = """
<payment>
<type>Web Payment</type>
<action>sale</action>
<station>API</station>
<amount>50</amount>
<payment_method>VISA</payment_method>
</payment>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Lock the order before making the change.
lock_response = session.request('LOCK', order_url)
assert lock_response.status_code == 200
# Send the request to update the order.
post_response = session.post(order_url + 'payments/', data=payment_xml)
assert post_response.status_code == 201
# Unlock the order after the change is complete.
unlock_response = session.request('UNLOCK', order_url)
assert unlock_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Print the revised product.
response_xml = minidom.parseString(post_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<response>
<payment id="16" uri="https://localhost:9630/api/orders/63/payments/16/">
<type>Web Payment</type>
<payment_method>VISA</payment_method>
<datetime_created>2017-07-20T15:50:25.714655</datetime_created>
<datetime_modified>2017-07-20T15:50:25.714053</datetime_modified>
<exported/>
<posted/>
<flags>
<exported>false</exported>
<posted>false</posted>
<voided>false</voided>
</flags>
<number/>
<source id="O-63">Natsu Dragneel-09:10AM</source>
<amount>50</amount>
<tendered/>
<authcode/>
<avs_result/>
<till/>
<signature_photo/>
</payment>
<order full_render="false" id="63" uri="https://localhost:9630/api/orders/63/">
<totals>
<subtotal>30.00</subtotal>
<tax>2.10</tax>
<credit>-65.00</credit>
<total>32.10</total>
</totals>
</order>
</response>
Note
There is no way to list payment methods through the external OnSite API. You will need to consult the setup on the OnSite client to identify the payment methods.
Managing Inventory for an Order¶
A POST
request to /api/orders/{order id}/lineitems/{line item id}/reservation/
is
used to reserve/release inventory for a product listed in an order.
This must be preceded by a LOCK
request to the same endpoint, and followed by an UNLOCK
request.
See Locking & Unlocking Resources.
Reserving Inventory¶
We need to specify the quantity and the Warehouse we are reserving from or releasing to. Available Inventory is Warehouse ID 0.
In this example we’ll reserve a quantity of 1 out of Available Inventory.
"""
Reserve inventory for an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_id = 60
line_item_id = 64
order_url = 'https://%s:%d/api/orders/%d/' % (ONSITE_HOST, ONSITE_PORT, order_id)
order_line_item_reservation_url = '%slineitems/%d/reservation/' % (order_url, line_item_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the product being reserved from inventory.
reservation_xml = """
<reservation>
<quantity>1</quantity>
<from>
<warehouse id="0"/>
</from>
</reservation>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Lock the order before making the change.
lock_response = session.request('LOCK', order_url)
assert lock_response.status_code == 200
# Send the request to reserve inventory on the line item.
post_response = session.post(order_line_item_reservation_url, data=reservation_xml)
assert post_response.status_code == 200
# Unlock the order after the change is complete.
unlock_response = session.request('UNLOCK', order_url)
assert unlock_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Print the revised product.
response_xml = minidom.parseString(post_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<response>
<lineitem full_render="true" id="64" uri="https://localhost:9630/api/orders/60/lineitems/64/">
<cost edited="false" total="0.00">0.000</cost>
<discount/>
<pricing_level/>
<profit_margin minimum="0.000"/>
<quantity>1.000</quantity>
<quantity_discount>false</quantity_discount>
<sell_price>10.000</sell_price>
<sells>
<sell>10.000</sell>
<base>10.000</base>
<total>10.00</total>
<sell_quantity_discount>10.000</sell_quantity_discount>
<sell_tax_inclusive>10.700</sell_tax_inclusive>
<sell_tax_inclusive_total>10.70</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>10.70</sell_tax_inclusive_discounted>
</sells>
<editable>false</editable>
<manual>false</manual>
<lineitem_product>
<product full_render="true" id="43" uri="https://localhost:9630/api/products/43/">
<class/>
<currency id="1" uri="https://localhost:9630/api/setup/currencies/1/"/>
<code>333-003-09:10AM</code>
<costs>
<cost/>
<average>0.000</average>
<raw/>
</costs>
<supplier_costs/>
<flags>
<current>true</current>
<editable>false</editable>
<gift_card>false</gift_card>
<inventoried>false</inventoried>
<new_cost>false</new_cost>
<new_import>false</new_import>
<new_update>false</new_update>
<no_live_rules>false</no_live_rules>
<no_profit>false</no_profit>
<serialized>false</serialized>
<web>false</web>
<editable_sell>false</editable_sell>
<master_model>false</master_model>
</flags>
<sell_price>10.000</sell_price>
<pricing_levels/>
<created>2017-07-12T09:10:07.735177</created>
<modified>2017-07-12T09:10:07.735537</modified>
<description>Lucy's Bikini-09:10AM</description>
<long_web_description/>
<family/>
<gl_product>
<asset/>
<cogs_expense/>
<income/>
<payable_expense/>
</gl_product>
<product_id>P-1042</product_id>
<import_id/>
<inventory>
<available>-4.000</available>
<reserved>1.000</reserved>
<coming_for_stock>0</coming_for_stock>
<coming_for_customer>0</coming_for_customer>
<warehouses>0.000</warehouses>
<in_transit>0.000</in_transit>
<total>-3.000</total>
</inventory>
<margin/>
<minimum_margin>0.000</minimum_margin>
<notes/>
<product_info>
<color/>
<height>0.000</height>
<length>0.000</length>
<size/>
<weight>0.000</weight>
<width>0.000</width>
</product_info>
<reorder>
<amount>0.000</amount>
<calc>0.000</calc>
<point>0.000</point>
<type>0</type>
</reorder>
<sells>
<sell>10.000</sell>
<sell_tax_inclusive/>
<sell_web/>
</sells>
<supplier/>
<supplier_code/>
<upc/>
<web>
<inventory/>
</web>
<keywords>
<keyword/>
<keyword/>
<keyword/>
</keywords>
<multi_store_label>43</multi_store_label>
<multi_store_master_label/>
<categories>
<pos/>
<web/>
</categories>
<related_products/>
<serial_numbers/>
<product_photos/>
<tax_exemption id="0" uri="https://localhost:9630/api/setup/tax_exemptions/0/">
<name>Default</name>
<taxes>
<tax id="1">
<exempt>false</exempt>
</tax>
<tax id="2">
<exempt>false</exempt>
</tax>
<tax id="3">
<exempt>false</exempt>
</tax>
<tax id="4">
<exempt>false</exempt>
</tax>
<tax id="5">
<exempt>false</exempt>
</tax>
</taxes>
<active>true</active>
</tax_exemption>
<master_product/>
</product>
<code>333-003-09:10AM</code>
<family/>
<description>Lucy's Bikini-09:10AM</description>
<class_name/>
<current>true</current>
<editable>false</editable>
<editable_sell>false</editable_sell>
<gift_card>false</gift_card>
<inventoried>false</inventoried>
<no_profit>false</no_profit>
<serialized>false</serialized>
</lineitem_product>
<tax_exemption id="0" uri="https://localhost:9630/api/setup/tax_exemptions/0/"/>
<taxes>
<tax id="1">
<exempt>false</exempt>
<total>0.70</total>
</tax>
<tax id="2">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="3">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="4">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="5">
<exempt>true</exempt>
<total>0.00</total>
</tax>
</taxes>
<status>Received</status>
<quantity_received>1.000</quantity_received>
</lineitem>
<order full_render="true" id="60" uri="https://localhost:9630/api/orders/60/">
<document_id>60</document_id>
<date_created>2017-07-12</date_created>
<datetime_created>2017-07-12T09:10:13.028297</datetime_created>
<date_modified>2017-07-20</date_modified>
<datetime_modified>2017-07-20T16:20:39.740804</datetime_modified>
<order_id>O-60</order_id>
<order_customer>
<customer/>
<mainname>Natsu Dragneel-09:10AM</mainname>
<mainphone/>
<phone_email/>
<contact/>
<contact_info/>
<discount>0.000</discount>
<pricing_level>0</pricing_level>
<terms_tax/>
<zip/>
<po/>
</order_customer>
<margin>100.00</margin>
<print_options>
<localizable_language full_render="true" id="0" uri="https://localhost:9630/api/setup/localizable_languages/0/">
<name>English</name>
<list_order>0</list_order>
</localizable_language>
<images>0</images>
<discounts>false</discounts>
</print_options>
<primary_user>
<user id="2" uri="https://localhost:9630/api/users/2/"/>
</primary_user>
<secondary_user>
<user/>
</secondary_user>
<printed_notes/>
<internal_notes/>
<shipping_method/>
<currency full_render="true" id="1" uri="https://localhost:9630/api/setup/currencies/1/">
<name>US</name>
<rate>1.000000</rate>
<symbol>$</symbol>
</currency>
<terms/>
<due>2017-07-12</due>
<import_id/>
<status>Partially Received</status>
<tax_code id="0" uri="https://localhost:9630/api/tax_codes/0/"/>
<taxes inclusive="false">
<tax_exempt>
<tax id="1" rate="7.00" total="1.40">false</tax>
<tax id="2" rate="0.00" total="0.00">false</tax>
<tax id="3" rate="0.00" total="0.00">false</tax>
<tax id="4" rate="0.00" total="0.00">false</tax>
<tax id="5" rate="0.00" total="0.00">false</tax>
</tax_exempt>
</taxes>
<pricing_level/>
<c_discount_percentage>0.000</c_discount_percentage>
<payments/>
<billing/>
<shipping/>
<lineitems>
<lineitem full_render="false" id="64" uri="https://localhost:9630/api/orders/60/lineitems/64/">
<quantity>1.000</quantity>
<sell_price>10.000</sell_price>
<sells>
<sell>10.000</sell>
<base>10.000</base>
<total>10.00</total>
<sell_quantity_discount>10.000</sell_quantity_discount>
<sell_tax_inclusive>10.700</sell_tax_inclusive>
<sell_tax_inclusive_total>10.70</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>10.70</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="43" uri="https://localhost:9630/api/products/43/"/>
<code>333-003-09:10AM</code>
<description>Lucy's Bikini-09:10AM</description>
</lineitem_product>
</lineitem>
<lineitem full_render="false" id="65" uri="https://localhost:9630/api/orders/60/lineitems/65/">
<quantity>1.000</quantity>
<sell_price>10.000</sell_price>
<sells>
<sell>10.000</sell>
<base>10.000</base>
<total>10.00</total>
<sell_quantity_discount>10.000</sell_quantity_discount>
<sell_tax_inclusive>10.700</sell_tax_inclusive>
<sell_tax_inclusive_total>10.70</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>10.70</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="43" uri="https://localhost:9630/api/products/43/"/>
<code>333-003-09:10AM</code>
<description>Lucy's Bikini-09:10AM</description>
</lineitem_product>
</lineitem>
</lineitems>
<flags>
<drop_shipment>false</drop_shipment>
</flags>
<totals>
<subtotal>20.00</subtotal>
<tax>1.40</tax>
<credit>0.00</credit>
<total>21.40</total>
</totals>
<web_order_number/>
<order_type>Customer</order_type>
</order>
</response>
Releasing Inventory¶
We need to specify the quantity and the Warehouse we are reserving from or releasing to. Available Inventory is Warehouse ID 0.
In this example we’ll release a quantity of 1 out of Available Inventory.
"""
Reserve inventory for an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_id = 60
line_item_id = 64
order_url = 'https://%s:%d/api/orders/%d/' % (ONSITE_HOST, ONSITE_PORT, order_id)
order_line_item_reservation_url = '%slineitems/%d/reservation/' % (order_url, line_item_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the product being released from inventory.
reservation_xml = """
<reservation>
<quantity>1</quantity>
<to>
<warehouse id="0"/>
</to>
</reservation>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Lock the order before making the change.
lock_response = session.request('LOCK', order_url)
assert lock_response.status_code == 200
# Send the request to release inventory on the line item.
post_response = session.post(order_line_item_reservation_url, data=reservation_xml)
assert post_response.status_code == 200
# Unlock the order after the change is complete.
unlock_response = session.request('UNLOCK', order_url)
assert unlock_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Print the revised product.
response_xml = minidom.parseString(post_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<response>
<lineitem full_render="true" id="64" uri="https://localhost:9630/api/orders/60/lineitems/64/">
<cost edited="false" total="0.00">0.000</cost>
<discount/>
<pricing_level/>
<profit_margin minimum="0.000"/>
<quantity>1.000</quantity>
<quantity_discount>false</quantity_discount>
<sell_price>10.000</sell_price>
<sells>
<sell>10.000</sell>
<base>10.000</base>
<total>10.00</total>
<sell_quantity_discount>10.000</sell_quantity_discount>
<sell_tax_inclusive>10.700</sell_tax_inclusive>
<sell_tax_inclusive_total>10.70</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>10.70</sell_tax_inclusive_discounted>
</sells>
<editable>false</editable>
<manual>false</manual>
<lineitem_product>
<product full_render="true" id="43" uri="https://localhost:9630/api/products/43/">
<class/>
<currency id="1" uri="https://localhost:9630/api/setup/currencies/1/"/>
<code>333-003-09:10AM</code>
<costs>
<cost/>
<average>0.000</average>
<raw/>
</costs>
<supplier_costs/>
<flags>
<current>true</current>
<editable>false</editable>
<gift_card>false</gift_card>
<inventoried>false</inventoried>
<new_cost>false</new_cost>
<new_import>false</new_import>
<new_update>false</new_update>
<no_live_rules>false</no_live_rules>
<no_profit>false</no_profit>
<serialized>false</serialized>
<web>false</web>
<editable_sell>false</editable_sell>
<master_model>false</master_model>
</flags>
<sell_price>10.000</sell_price>
<pricing_levels/>
<created>2017-07-12T09:10:07.735177</created>
<modified>2017-07-12T09:10:07.735537</modified>
<description>Lucy's Bikini-09:10AM</description>
<long_web_description/>
<family/>
<gl_product>
<asset/>
<cogs_expense/>
<income/>
<payable_expense/>
</gl_product>
<product_id>P-1042</product_id>
<import_id/>
<inventory>
<available>-3.000</available>
<reserved>0.000</reserved>
<coming_for_stock>0</coming_for_stock>
<coming_for_customer>0</coming_for_customer>
<warehouses>0.000</warehouses>
<in_transit>0.000</in_transit>
<total>-3.000</total>
</inventory>
<margin/>
<minimum_margin>0.000</minimum_margin>
<notes/>
<product_info>
<color/>
<height>0.000</height>
<length>0.000</length>
<size/>
<weight>0.000</weight>
<width>0.000</width>
</product_info>
<reorder>
<amount>0.000</amount>
<calc>0.000</calc>
<point>0.000</point>
<type>0</type>
</reorder>
<sells>
<sell>10.000</sell>
<sell_tax_inclusive/>
<sell_web/>
</sells>
<supplier/>
<supplier_code/>
<upc/>
<web>
<inventory/>
</web>
<keywords>
<keyword/>
<keyword/>
<keyword/>
</keywords>
<multi_store_label>43</multi_store_label>
<multi_store_master_label/>
<categories>
<pos/>
<web/>
</categories>
<related_products/>
<serial_numbers/>
<product_photos/>
<tax_exemption id="0" uri="https://localhost:9630/api/setup/tax_exemptions/0/">
<name>Default</name>
<taxes>
<tax id="1">
<exempt>false</exempt>
</tax>
<tax id="2">
<exempt>false</exempt>
</tax>
<tax id="3">
<exempt>false</exempt>
</tax>
<tax id="4">
<exempt>false</exempt>
</tax>
<tax id="5">
<exempt>false</exempt>
</tax>
</taxes>
<active>true</active>
</tax_exemption>
<master_product/>
</product>
<code>333-003-09:10AM</code>
<family/>
<description>Lucy's Bikini-09:10AM</description>
<class_name/>
<current>true</current>
<editable>false</editable>
<editable_sell>false</editable_sell>
<gift_card>false</gift_card>
<inventoried>false</inventoried>
<no_profit>false</no_profit>
<serialized>false</serialized>
</lineitem_product>
<tax_exemption id="0" uri="https://localhost:9630/api/setup/tax_exemptions/0/"/>
<taxes>
<tax id="1">
<exempt>false</exempt>
<total>0.70</total>
</tax>
<tax id="2">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="3">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="4">
<exempt>true</exempt>
<total>0.00</total>
</tax>
<tax id="5">
<exempt>true</exempt>
<total>0.00</total>
</tax>
</taxes>
<status>Requested</status>
<quantity_received>0.000</quantity_received>
</lineitem>
<order full_render="true" id="60" uri="https://localhost:9630/api/orders/60/">
<document_id>60</document_id>
<date_created>2017-07-12</date_created>
<datetime_created>2017-07-12T09:10:13.028297</datetime_created>
<date_modified>2017-07-20</date_modified>
<datetime_modified>2017-07-20T16:23:33.657255</datetime_modified>
<order_id>O-60</order_id>
<order_customer>
<customer/>
<mainname>Natsu Dragneel-09:10AM</mainname>
<mainphone/>
<phone_email/>
<contact/>
<contact_info/>
<discount>0.000</discount>
<pricing_level>0</pricing_level>
<terms_tax/>
<zip/>
<po/>
</order_customer>
<margin>100.00</margin>
<print_options>
<localizable_language full_render="true" id="0" uri="https://localhost:9630/api/setup/localizable_languages/0/">
<name>English</name>
<list_order>0</list_order>
</localizable_language>
<images>0</images>
<discounts>false</discounts>
</print_options>
<primary_user>
<user id="2" uri="https://localhost:9630/api/users/2/"/>
</primary_user>
<secondary_user>
<user/>
</secondary_user>
<printed_notes/>
<internal_notes/>
<shipping_method/>
<currency full_render="true" id="1" uri="https://localhost:9630/api/setup/currencies/1/">
<name>US</name>
<rate>1.000000</rate>
<symbol>$</symbol>
</currency>
<terms/>
<due>2017-07-12</due>
<import_id/>
<status>Requested</status>
<tax_code id="0" uri="https://localhost:9630/api/tax_codes/0/"/>
<taxes inclusive="false">
<tax_exempt>
<tax id="1" rate="7.00" total="1.40">false</tax>
<tax id="2" rate="0.00" total="0.00">false</tax>
<tax id="3" rate="0.00" total="0.00">false</tax>
<tax id="4" rate="0.00" total="0.00">false</tax>
<tax id="5" rate="0.00" total="0.00">false</tax>
</tax_exempt>
</taxes>
<pricing_level/>
<c_discount_percentage>0.000</c_discount_percentage>
<payments/>
<billing/>
<shipping/>
<lineitems>
<lineitem full_render="false" id="64" uri="https://localhost:9630/api/orders/60/lineitems/64/">
<quantity>1.000</quantity>
<sell_price>10.000</sell_price>
<sells>
<sell>10.000</sell>
<base>10.000</base>
<total>10.00</total>
<sell_quantity_discount>10.000</sell_quantity_discount>
<sell_tax_inclusive>10.700</sell_tax_inclusive>
<sell_tax_inclusive_total>10.70</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>10.70</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="43" uri="https://localhost:9630/api/products/43/"/>
<code>333-003-09:10AM</code>
<description>Lucy's Bikini-09:10AM</description>
</lineitem_product>
</lineitem>
<lineitem full_render="false" id="65" uri="https://localhost:9630/api/orders/60/lineitems/65/">
<quantity>1.000</quantity>
<sell_price>10.000</sell_price>
<sells>
<sell>10.000</sell>
<base>10.000</base>
<total>10.00</total>
<sell_quantity_discount>10.000</sell_quantity_discount>
<sell_tax_inclusive>10.700</sell_tax_inclusive>
<sell_tax_inclusive_total>10.70</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>10.70</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="43" uri="https://localhost:9630/api/products/43/"/>
<code>333-003-09:10AM</code>
<description>Lucy's Bikini-09:10AM</description>
</lineitem_product>
</lineitem>
</lineitems>
<flags>
<drop_shipment>false</drop_shipment>
</flags>
<totals>
<subtotal>20.00</subtotal>
<tax>1.40</tax>
<credit>0.00</credit>
<total>21.40</total>
</totals>
<web_order_number/>
<order_type>Customer</order_type>
</order>
</response>
Cancelling an Order¶
A POST
request to /api/orders/{order id}/cancel/
is used to cancel an order.
This must be preceded by a LOCK
request to the same endpoint, and followed by an UNLOCK
request.
See Locking & Unlocking Resources.
"""
Cancel an order using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_id = 59
order_url = 'https://%s:%d/api/orders/%d/' % (ONSITE_HOST, ONSITE_PORT, order_id)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the product being released from inventory.
cancel_xml = """
<order_cancellation/>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Lock the order before making the change.
lock_response = session.request('LOCK', order_url)
assert lock_response.status_code == 200
# Send the request to cancel the order.
post_response = session.post(order_url + 'cancel/', data=cancel_xml)
assert post_response.status_code == 200
# Unlock the order after the change is complete.
unlock_response = session.request('UNLOCK', order_url)
assert unlock_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Print the revised product.
response_xml = minidom.parseString(post_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<response>
<order full_render="true" id="59" uri="https://localhost:9630/api/orders/59/">
<document_id>59</document_id>
<date_created>2017-07-12</date_created>
<datetime_created>2017-07-12T09:10:12.235172</datetime_created>
<date_modified>2017-07-20</date_modified>
<datetime_modified>2017-07-20T16:29:42.307302</datetime_modified>
<order_id>O-59</order_id>
<order_customer>
<customer/>
<mainname>Natsu Dragneel-09:10AM</mainname>
<mainphone/>
<phone_email/>
<contact/>
<contact_info/>
<discount>0.000</discount>
<pricing_level>0</pricing_level>
<terms_tax/>
<zip/>
<po/>
</order_customer>
<margin>100.00</margin>
<print_options>
<localizable_language full_render="true" id="0" uri="https://localhost:9630/api/setup/localizable_languages/0/">
<name>English</name>
<list_order>0</list_order>
</localizable_language>
<images>0</images>
<discounts>false</discounts>
</print_options>
<primary_user>
<user id="2" uri="https://localhost:9630/api/users/2/"/>
</primary_user>
<secondary_user>
<user/>
</secondary_user>
<printed_notes/>
<internal_notes/>
<shipping_method/>
<currency full_render="true" id="1" uri="https://localhost:9630/api/setup/currencies/1/">
<name>US</name>
<rate>1.000000</rate>
<symbol>$</symbol>
</currency>
<terms/>
<due>2017-07-12</due>
<import_id/>
<status>Cancelled</status>
<tax_code id="0" uri="https://localhost:9630/api/tax_codes/0/"/>
<taxes inclusive="false">
<tax_exempt>
<tax id="1" rate="7.00" total="5.25">false</tax>
<tax id="2" rate="0.00" total="0.00">false</tax>
<tax id="3" rate="0.00" total="0.00">false</tax>
<tax id="4" rate="0.00" total="0.00">false</tax>
<tax id="5" rate="0.00" total="0.00">false</tax>
</tax_exempt>
</taxes>
<pricing_level/>
<c_discount_percentage>0.000</c_discount_percentage>
<payments/>
<billing/>
<shipping/>
<lineitems>
<lineitem full_render="false" id="62" uri="https://localhost:9630/api/orders/59/lineitems/62/">
<quantity>1.000</quantity>
<sell_price>15.000</sell_price>
<sells>
<sell>15.000</sell>
<base>10.000</base>
<total>15.00</total>
<sell_quantity_discount>10.000</sell_quantity_discount>
<sell_tax_inclusive>10.700</sell_tax_inclusive>
<sell_tax_inclusive_total>16.05</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>16.05</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="43" uri="https://localhost:9630/api/products/43/"/>
<code>333-003-09:10AM</code>
<description>Lucy's Bikini-09:10AM</description>
</lineitem_product>
</lineitem>
<lineitem full_render="false" id="63" uri="https://localhost:9630/api/orders/59/lineitems/63/">
<quantity>1.000</quantity>
<sell_price>60.000</sell_price>
<sells>
<sell>60.000</sell>
<base>10.000</base>
<total>60.00</total>
<sell_quantity_discount>10.000</sell_quantity_discount>
<sell_tax_inclusive>10.700</sell_tax_inclusive>
<sell_tax_inclusive_total>64.20</sell_tax_inclusive_total>
<sell_tax_inclusive_discounted>64.20</sell_tax_inclusive_discounted>
</sells>
<lineitem_product>
<product id="43" uri="https://localhost:9630/api/products/43/"/>
<code>333-003-09:10AM</code>
<description>Lucy's Bikini-09:10AM</description>
</lineitem_product>
</lineitem>
</lineitems>
<flags>
<drop_shipment>false</drop_shipment>
</flags>
<totals>
<subtotal>75.00</subtotal>
<tax>5.25</tax>
<credit>0.00</credit>
<total>80.25</total>
</totals>
<web_order_number/>
<order_type>Customer</order_type>
</order>
</response>
Searching Orders¶
A POST
request to /api/orders/search/
is used to search orders. The POST
request payload specifies
what invoice information to return (columns) and what to search by (filters). Pagination is supported with
the search query.
A GET
request to /api/orders/search/
is used to obtain the list of columns and filters.
Listing Search Columns and Filters¶
A GET
request to /api/orders/search/
is used to obtain the list of columns and filters.
These results can be cached if desired.
"""
Get the list of search filters and columns for orders using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
customer_search_url = 'https://%s:%d/api/orders/search/' % (ONSITE_HOST, ONSITE_PORT)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Send the request to get the list of columns/filters.
get_response = session.get(customer_search_url)
assert get_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Print the list of columns/filters.
response_xml = minidom.parseString(get_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<search_criteria uri="https://localhost:9630/api/orders/search/">
<columns>
<column id="lsserver.search.column.id">
<name>
<localizable_message type="lsserver.search.column.id">
<fields/>
<plain_message>ID</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>true</default>
<sort_default>true</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.date">
<name>
<localizable_message type="lsserver.search.column.date">
<fields/>
<plain_message>Date</plain_message>
</localizable_message>
</name>
<type>DATE</type>
<required>false</required>
<default>true</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.customer">
<name>
<localizable_message type="lsserver.search.column.customer">
<fields/>
<plain_message>Customer</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>true</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.phone">
<name>
<localizable_message type="lsserver.search.column.phone">
<fields/>
<plain_message>Phone</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>true</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.po">
<name>
<localizable_message type="lsserver.search.column.po">
<fields/>
<plain_message>PO</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>true</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.user">
<name>
<localizable_message type="lsserver.search.column.user">
<fields/>
<plain_message>User</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>true</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.status">
<name>
<localizable_message type="lsserver.search.column.status">
<fields/>
<plain_message>Status</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>true</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.total">
<name>
<localizable_message type="lsserver.search.column.total">
<fields/>
<plain_message>Total</plain_message>
</localizable_message>
</name>
<type>MONEY</type>
<required>false</required>
<default>true</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>true</can_summarize>
</column>
<column id="lsserver.search.column.modified">
<name>
<localizable_message type="lsserver.search.column.modified">
<fields/>
<plain_message>Modified</plain_message>
</localizable_message>
</name>
<type>DATETIME</type>
<required>false</required>
<default>false</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.created">
<name>
<localizable_message type="lsserver.search.column.created">
<fields/>
<plain_message>Created</plain_message>
</localizable_message>
</name>
<type>DATETIME</type>
<required>false</required>
<default>false</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.drop_shipment">
<name>
<localizable_message type="lsserver.search.column.drop_shipment">
<fields/>
<plain_message>Drop Shipment</plain_message>
</localizable_message>
</name>
<type>BOOLEAN</type>
<required>false</required>
<default>false</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.shipping_method">
<name>
<localizable_message type="lsserver.search.column.shipping_method">
<fields/>
<plain_message>Shipping Method</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>false</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.terms">
<name>
<localizable_message type="lsserver.search.column.terms">
<fields/>
<plain_message>Terms</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>false</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.currency">
<name>
<localizable_message type="lsserver.search.column.currency">
<fields/>
<plain_message>Currency</plain_message>
</localizable_message>
</name>
<type>STRING</type>
<required>false</required>
<default>false</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.deposit_amount">
<name>
<localizable_message type="lsserver.search.column.deposit_amount">
<fields/>
<plain_message>Deposit Amount</plain_message>
</localizable_message>
</name>
<type>MONEY</type>
<required>false</required>
<default>false</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
<column id="lsserver.search.column.deposit_status">
<name>
<localizable_message type="lsserver.search.column.deposit_status">
<fields/>
<plain_message>Deposit Status</plain_message>
</localizable_message>
</name>
<type>ENUM</type>
<required>false</required>
<default>false</default>
<sort_default>false</sort_default>
<sort_default_order_by>ASC</sort_default_order_by>
<can_summarize>false</can_summarize>
</column>
</columns>
<filters>
<filter id="lsserver.search.filters.created_date">
<name>
<localizable_message type="lsserver.search.filters.created_date">
<fields/>
<plain_message>Created Date</plain_message>
</localizable_message>
</name>
<type>DATE</type>
</filter>
<filter id="lsserver.search.filters.user">
<name>
<localizable_message type="lsserver.search.filters.user">
<fields/>
<plain_message>User</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.status">
<name>
<localizable_message type="lsserver.search.filters.status">
<fields/>
<plain_message>Status</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.deposit_amount">
<name>
<localizable_message type="lsserver.search.filters.deposit_amount">
<fields/>
<plain_message>Deposit Amount</plain_message>
</localizable_message>
</name>
<type>MONEY</type>
</filter>
<filter id="lsserver.search.filters.deposit_status">
<name>
<localizable_message type="lsserver.search.filters.deposit_status">
<fields/>
<plain_message>Deposit Status</plain_message>
</localizable_message>
</name>
<type>ENUM</type>
<enum_values>
<enum_value>
<name>
<raw>NONE</raw>
</name>
<value>NONE</value>
</enum_value>
<enum_value>
<name>
<raw>PARTIAL</raw>
</name>
<value>PARTIAL</value>
</enum_value>
<enum_value>
<name>
<raw>FULL</raw>
</name>
<value>FULL</value>
</enum_value>
</enum_values>
</filter>
<filter id="lsserver.search.filters.drop_shipment">
<name>
<localizable_message type="lsserver.search.filters.drop_shipment">
<fields/>
<plain_message>Drop Shipment</plain_message>
</localizable_message>
</name>
<type>BOOLEAN</type>
</filter>
<filter id="lsserver.search.filters.order_id">
<name>
<localizable_message type="lsserver.search.filters.order_id">
<fields/>
<plain_message>Order ID</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.customer_id">
<name>
<localizable_message type="lsserver.search.filters.customer_id">
<fields/>
<plain_message>Customer ID</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.customer_name">
<name>
<localizable_message type="lsserver.search.filters.customer_name">
<fields/>
<plain_message>Customer Name</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.customer_phone">
<name>
<localizable_message type="lsserver.search.filters.customer_phone">
<fields/>
<plain_message>Customer Phone</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.customer_po">
<name>
<localizable_message type="lsserver.search.filters.customer_po">
<fields/>
<plain_message>Customer PO</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.product_code">
<name>
<localizable_message type="lsserver.search.filters.product_code">
<fields/>
<plain_message>Product Code</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.product_description">
<name>
<localizable_message type="lsserver.search.filters.product_description">
<fields/>
<plain_message>Product Description</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.product_id">
<name>
<localizable_message type="lsserver.search.filters.product_id">
<fields/>
<plain_message>Product ID</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.upc">
<name>
<localizable_message type="lsserver.search.filters.upc">
<fields/>
<plain_message>UPC</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.product_class">
<name>
<localizable_message type="lsserver.search.filters.product_class">
<fields/>
<plain_message>Product Class</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.product_family">
<name>
<localizable_message type="lsserver.search.filters.product_family">
<fields/>
<plain_message>Product Family</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.product_size">
<name>
<localizable_message type="lsserver.search.filters.product_size">
<fields/>
<plain_message>Product Size</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.product_color">
<name>
<localizable_message type="lsserver.search.filters.product_color">
<fields/>
<plain_message>Product Color</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.printed_notes">
<name>
<localizable_message type="lsserver.search.filters.printed_notes">
<fields/>
<plain_message>Printed Notes</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.internal_notes">
<name>
<localizable_message type="lsserver.search.filters.internal_notes">
<fields/>
<plain_message>Internal Notes</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</filter>
<filter id="lsserver.search.filters.modified_date">
<name>
<localizable_message type="lsserver.search.filters.modified_date">
<fields/>
<plain_message>Modified Date</plain_message>
</localizable_message>
</name>
<type>DATE</type>
</filter>
</filters>
</search_criteria>
Search by Date¶
A POST
request to /api/orders/search/
is used to search orders.
"""
Search orders using the OnSite API.
"""
import requests
from xml.dom import minidom
# Customize these to your install.
ONSITE_HOST = 'localhost'
ONSITE_PORT = 9630
ONSITE_USERNAME = 'lightspeed'
ONSITE_PASSWORD = 'admin'
APP_ID = 'com.lightspeed.onsite.demo'
APP_VERSION = '1.0'
APP_PRIVATE_ID = '12345678-90ab-cdef-1234-567890abcdef'
order_search_url = 'https://%s:%d/api/orders/search/' % (ONSITE_HOST, ONSITE_PORT)
logout_url = 'https://%s:%d/api/sessions/current/logout/' % (ONSITE_HOST, ONSITE_PORT)
# This is the search information.
search_xml = """
<search>
<page>
<offset>0</offset>
<count>5</count>
</page>
<search_query>
<columns>
<column id="lsserver.search.column.id"/>
<column id="lsserver.search.column.created"/>
<column id="lsserver.search.column.total"/>
<column id="lsserver.search.column.status"/>
</columns>
<sort_by_column>
<column id="lsserver.search.column.created"/>
<order_by>ASC</order_by>
</sort_by_column>
<filters>lsserver.search.filters.created_date > '2017-07-05'</filters>
</search_query>
</search>
"""
# Create a session. This will persist cookies across all requests.
session = requests.Session()
session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)
session.headers.update({
'user-agent': '%s/%s' % (APP_ID, APP_VERSION),
'x-pappid': APP_PRIVATE_ID})
session.verify = False
# Send the request to search the orders.
post_response = session.post(order_search_url, data=search_xml)
assert post_response.status_code == 200
# Log out.
logout_response = session.post(logout_url)
assert logout_response.status_code == 204
# Print the search results.
response_xml = minidom.parseString(post_response.text)
print(response_xml.toprettyxml())
<!-- Response -->
<?xml version="1.0" ?>
<data>
<info>
<total_count>74</total_count>
</info>
<columns>
<column>
<name>
<localizable_message type="lsserver.search.column.id">
<fields/>
<plain_message>ID</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</column>
<column>
<name>
<localizable_message type="lsserver.search.column.created">
<fields/>
<plain_message>Created</plain_message>
</localizable_message>
</name>
<type>DATETIME</type>
</column>
<column>
<name>
<localizable_message type="lsserver.search.column.total">
<fields/>
<plain_message>Total</plain_message>
</localizable_message>
</name>
<type>MONEY</type>
</column>
<column>
<name>
<localizable_message type="lsserver.search.column.status">
<fields/>
<plain_message>Status</plain_message>
</localizable_message>
</name>
<type>STRING</type>
</column>
</columns>
<rows>
<row>
<links>
<link>
<order id="1" uri="https://localhost:9630/api/orders/1/"/>
</link>
</links>
<cell>
<type>STRING</type>
<value>O-1</value>
</cell>
<cell>
<type>DATETIME</type>
<value>2017-07-07 13:00:59.668605</value>
</cell>
<cell>
<type>MONEY</type>
<value>0.00</value>
</cell>
<cell>
<type>STRING</type>
<value>Invoiced</value>
</cell>
</row>
<row>
<links>
<link>
<order id="2" uri="https://localhost:9630/api/orders/2/"/>
</link>
</links>
<cell>
<type>STRING</type>
<value>O-2</value>
</cell>
<cell>
<type>DATETIME</type>
<value>2017-07-07 13:03:49.029396</value>
</cell>
<cell>
<type>MONEY</type>
<value>50.00</value>
</cell>
<cell>
<type>STRING</type>
<value>Invoiced</value>
</cell>
</row>
<row>
<links>
<link>
<order id="3" uri="https://localhost:9630/api/orders/3/"/>
</link>
</links>
<cell>
<type>STRING</type>
<value>O-3</value>
</cell>
<cell>
<type>DATETIME</type>
<value>2017-07-07 13:15:20.524994</value>
</cell>
<cell>
<type>MONEY</type>
<value>10.70</value>
</cell>
<cell>
<type>STRING</type>
<value>Invoiced</value>
</cell>
</row>
<row>
<links>
<link>
<order id="4" uri="https://localhost:9630/api/orders/4/"/>
</link>
</links>
<cell>
<type>STRING</type>
<value>O-4</value>
</cell>
<cell>
<type>DATETIME</type>
<value>2017-07-11 14:35:48.306297</value>
</cell>
<cell>
<type>MONEY</type>
<value>16.48</value>
</cell>
<cell>
<type>STRING</type>
<value>Requested</value>
</cell>
</row>
<row>
<links>
<link>
<order id="5" uri="https://localhost:9630/api/orders/5/"/>
</link>
</links>
<cell>
<type>STRING</type>
<value>O-5</value>
</cell>
<cell>
<type>DATETIME</type>
<value>2017-07-11 14:35:48.535543</value>
</cell>
<cell>
<type>MONEY</type>
<value>45.48</value>
</cell>
<cell>
<type>STRING</type>
<value>Received</value>
</cell>
</row>
</rows>
</data>