### Complete Configuration Example with Logging Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md An example demonstrating a comprehensive setup including API key retrieval from environment variables, logging configuration, and Shipday client initialization. ```python import os import logging from shipday import Shipday from shipday.exceptions import ShipdayException # Configure logging to see request details logging.basicConfig(level=logging.DEBUG) ``` -------------------------------- ### Install Shipday SDK Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md Installs the Shipday SDK and its dependencies using pip. Alternatively, install only the requests library if the SDK is not needed. ```bash pip install shipday ``` ```bash pip install requests>=2.20 ``` -------------------------------- ### Complete OrderCost Example Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_cost.md A comprehensive example demonstrating the creation of an OrderCost object, accessing and modifying its properties, retrieving the API body, and verifying the cost. Includes error handling for validation. ```python from shipday.order import OrderCost # Create cost breakdown cost = OrderCost( tips=5.0, tax=8.50, discount=2.0, delivery_fee=4.99, total=65.49 ) # Access cost properties print(f"Subtotal (items): ${cost.total - cost.tax - cost.tips - cost.delivery_fee + cost.discount}") print(f"Tax: ${cost.tax}") print(f"Delivery Fee: ${cost.delivery_fee}") print(f"Discount: -${cost.discount}") print(f"Tips: +${cost.tips}") print(f"Total: ${cost.total}") # Modify costs cost.tips = 7.50 cost.discount = 3.00 # Update total accordingly cost.total = 67.99 # Get API representation api_data = cost.get_body() print(api_data) # Validate cost try: cost.verify() print("Cost is valid") except Exception as e: print(f"Invalid: {e}") ``` -------------------------------- ### Install Shipday Python SDK Source: https://github.com/shipday/shipday-python-sdk/blob/main/README.md Install the Shipday Python SDK using pip. Ensure you have Python 3.6 or higher. ```bash pip install shipday ``` -------------------------------- ### Complete Customer Object Example Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/customer.md Demonstrates the creation of a Customer object with full details, accessing its properties, modifying them, and obtaining the API representation. ```python from shipday.order import Customer, Address # Create customer with full details customer = Customer( name='Alice Johnson', email='alice@example.com', phone_number='+1-415-555-0199', address=Address( unit='Suite 200', street='789 Oak Avenue', city='San Francisco', state='California', zip='94109', country='USA', latitude=37.7844, longitude=-122.4087 ) ) # Access customer data print(f"Name: {customer.name}") print(f"Email: {customer.email}") print(f"Phone: {customer.phone_number}") print(f"Address: {customer.address.get_single_line()}") # Modify customer details customer.email = 'alice.johnson@example.com' customer.phone_number = '+1-415-555-0200' # Get API representation api_data = customer.get_body() print(api_data) ``` -------------------------------- ### Create and Submit an Order Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/INDEX.md Example of creating a new order with customer, pickup, items, and cost details, then submitting it via the OrderService. ```python from shipday.order import Order, Address, Customer, Pickup, OrderItem, OrderCost order = Order(orderNumber='100') order.customer = Customer(name='John', phone_number='+1-555-0123', address=Address(...)) order.pickup = Pickup(name='Restaurant', address=Address(...)) order.order_items = [OrderItem(name='Pizza', unit_price=15.0, quantity=1)] order.order_cost = OrderCost(total=20.0) response = my_shipday.OrderService.insert_order(order) ``` -------------------------------- ### Example JSON Request Format Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md Illustrates the expected JSON structure for requests sent to the Shipday API. ```json { "field1": "value1", "field2": 123 } ``` -------------------------------- ### Complete Order Query Example Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_query.md Demonstrates how to use OrderQuery to retrieve orders within a specific time range and status, and how to perform paginated queries. ```python from shipday import Shipday from shipday.order import OrderQuery, OrderStatus from datetime import datetime, timedelta my_shipday = Shipday(api_key='your_api_key') # Query orders from last 24 hours with ACTIVE status query = OrderQuery() query.start_time = datetime.now() - timedelta(days=1) query.end_time = datetime.now() query.order_status = OrderStatus.ACTIVE orders = my_shipday.OrderService.query(query=query) print(f"Active orders in last 24 hours: {len(orders)}") for order in orders: print(f"Order #{order.get('orderNumber')}: {order.get('status')}") # Query with pagination query2 = OrderQuery() query2.start_cursor = 0 query2.end_cursor = 100 orders2 = my_shipday.OrderService.query(query=query2) ``` -------------------------------- ### Get Shipday SDK Version Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md Retrieve the currently installed version of the Shipday Python SDK by importing the VERSION constant. ```python from shipday.version import VERSION print(f"Shipday SDK version: {VERSION}") ``` -------------------------------- ### Setting OrderQuery start_time Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_query.md Sets or gets the start time for the order query. This property is readable and writable and must be a datetime object or None. ```python from datetime import datetime query.start_time = datetime.now() start = query.start_time ``` -------------------------------- ### Complete Carrier Management Example Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/carrier_request.md Demonstrates the full lifecycle of a carrier using the Shipday Python SDK, including creation, submission, modification, and validation. ```python from shipday import Shipday from shipday.carrier import CarrierRequest my_shipday = Shipday(api_key='your_api_key') # Create a new carrier carrier = CarrierRequest( name='Bob Wilson', email='bob.wilson@example.com', phone_number='+1-555-0456' ) # Submit the carrier response = my_shipday.CarrierService.add_carrier(carrier) print(f"Carrier created: {response}") # Modify carrier details carrier.email = 'bob.wilson.new@example.com' carrier.phone_number = '+1-555-0457' # Get API representation api_data = carrier.get_body() print(api_data) # Validate carrier try: carrier.verify() print("Carrier is valid") except Exception as e: print(f"Invalid: {e}") ``` -------------------------------- ### Complete OrderItem Example Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_item.md Illustrates the creation, property access, modification, API body retrieval, and verification of OrderItem instances, including both detailed and minimal configurations. ```python from shipday.order import OrderItem # Create item with all details item1 = OrderItem( name='Margherita Pizza', unit_price=16.99, quantity=2, add_ons='Extra garlic', detail='Thin crust' ) # Create item with minimal info item2 = OrderItem( name='House Salad', unit_price=8.99, quantity=1 ) # Access item properties print(f"Item: {item1.name}") print(f"Price: ${item1.unit_price}") print(f"Qty: {item1.quantity}") print(f"Total: ${item1.unit_price * item1.quantity}") # Modify item item2.add_ons = 'Dressing on side' item2.detail = 'No croutons' # Get API representation api_data = item1.get_body() print(api_data) # Validate item try: item1.verify() print("Item is valid") except Exception as e: print(f"Invalid: {e}") ``` -------------------------------- ### Complete Pickup Example Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/pickup.md Demonstrates the full lifecycle of a Pickup object, including creation with full details, accessing and modifying attributes, and converting to API format. Also shows creating a minimal pickup and verifying it. ```python from shipday.order import Pickup, Address # Create pickup location with full details pickup = Pickup( name='Central Kitchen', phone_number='+1-415-555-0123', address=Address( street='456 Market Street', city='San Francisco', state='California', zip='94102', country='USA', latitude=37.7900, longitude=-122.3950 ) ) # Access pickup details print(f"Location: {pickup.name}") print(f"Phone: {pickup.phone_number}") print(f"Address: {pickup.address.get_single_line()}") # Modify pickup details pickup.phone_number = '+1-415-555-0124' # Get API representation api_data = pickup.get_body() print(api_data) # Create minimal pickup with just required fields minimal_pickup = Pickup( name='Store #5', address=Address( street='123 Oak Lane', city='Los Angeles', country='USA' ) ) minimal_pickup.verify() ``` -------------------------------- ### Setting OrderQuery start_cursor Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_query.md Sets or gets the pagination start cursor for the order query. This property is readable and writable and must be an integer or None. ```python query.start_cursor = 0 cursor = query.start_cursor ``` -------------------------------- ### Accessing and Modifying Customer Phone Number Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/customer.md Demonstrates how to get and set the 'phone_number' property for a Customer. ```python customer.phone_number = '+1-555-0123' phone = customer.phone_number ``` -------------------------------- ### Get All Orders Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_service.md Retrieves a list of all orders from your Shipday account. Useful for getting an overview of all active and historical orders. ```python from shipday import Shipday my_shipday = Shipday(api_key='your_api_key') orders = my_shipday.OrderService.get_orders() print(f"Total orders: {len(orders)}") for order in orders: print(f"Order #{order['orderNumber']}: Status {order.get('status')}") ``` -------------------------------- ### Accessing and Setting Pickup Location Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Illustrates how to set and get pickup location details for an Order. The pickup attribute must be an instance of the Pickup class. ```python order.pickup = Pickup(...) pickup = order.pickup ``` -------------------------------- ### Handle Order Validation Errors Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/errors.md Example of catching a ShipdayException during order verification when required fields are missing. ```python from shipday import Shipday from shipday.exceptions import ShipdayException my_shipday = Shipday(api_key='your_api_key') try: # Order without required fields order = Order(orderNumber=None) order.verify() except ShipdayException as e: print(f"Validation error: {e}") ``` -------------------------------- ### Example JSON Response Format Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md Shows the structure of a successful JSON response from the Shipday API, including an ID, status, and data payload. ```json { "id": 12345, "status": "success", "data": {...} } ``` -------------------------------- ### Get API Key from Environment Variable Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md It is recommended to store your Shipday API key in an environment variable (e.g., SHIPDAY_API_KEY) for security and flexibility. ```python import os from shipday import Shipday # Get API key from environment api_key = os.getenv('SHIPDAY_API_KEY') if not api_key: raise ValueError("SHIPDAY_API_KEY environment variable is required") my_shipday = Shipday(api_key=api_key) ``` -------------------------------- ### Get Active On-Demand Delivery Services Source: https://github.com/shipday/shipday-python-sdk/blob/main/README.md Use get_active_services() to retrieve the names of services currently available to your account. ```python my_shipday.OnDemandDeliveryService.get_active_services() ``` -------------------------------- ### Handle Shipday SDK Exceptions Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/errors.md Example of catching and printing a ShipdayException when an order cannot be retrieved due to invalid parameters like a None order number. ```python from shipday import Shipday from shipday.exceptions import ShipdayException my_shipday = Shipday(api_key='your_api_key') try: orders = my_shipday.OrderService.get_order(order_number=None) except ShipdayException as e: print(f"Error retrieving order: {e}") ``` -------------------------------- ### Handle API Rate Limit Exceeded Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/errors.md Example of catching ShipdayRateLimitException when the API rate limit is exceeded, suggesting implementation of backoff/retry logic. ```python from shipday import Shipday from shipday.exceptions import ShipdayRateLimitException my_shipday = Shipday(api_key='your_api_key') try: # This may trigger rate limit if called too many times for i in range(1000): my_shipday.OrderService.get_orders() except ShipdayRateLimitException as e: print(f"Rate limit exceeded: {e}") # Implement backoff/retry logic ``` -------------------------------- ### Handle Order Creation with Invalid Data Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/errors.md Example of catching ShipdayException when attempting to insert an order with missing required fields, prompting user feedback. ```python from shipday import Shipday from shipday.order import Order from shipday.exceptions import ShipdayException my_shipday = Shipday(api_key='your_api_key') try: # Missing required fields bad_order = Order() my_shipday.OrderService.insert_order(bad_order) except ShipdayException as e: print(f"Cannot create order: {e}") # Handle error: inform user which fields are required ``` -------------------------------- ### Getting Customer Data as Dictionary Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/customer.md Retrieves customer information formatted as a dictionary suitable for API requests. Includes details like name, address, email, and phone number. ```python customer = Customer( name='Jane Smith', email='jane@example.com', phone_number='+1-555-0123', address=Address(...) ) body = customer.get_body() print(body) ``` -------------------------------- ### Getting Address Components as Dictionary Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Retrieves the address components (unit, street, city, state, zip, country) as a dictionary. Only fields that have been populated are included in the returned dictionary. ```python address = Address( street='123 Main St', city='San Francisco', state='CA', zip='94102', country='USA' ) breakdown = address.get_breakdown() # Returns: {'street': '123 Main St', 'city': 'San Francisco', 'state': 'CA', 'zip': '94102', 'country': 'USA'} ``` -------------------------------- ### Query Orders by Time Range Source: https://github.com/shipday/shipday-python-sdk/blob/main/README.md Query orders within a specific time range using the OrderService.query() method. Create an OrderQuery object and set the start_time. This example retrieves orders from the last 24 hours. ```python from shipday.order import OrderQuery query = OrderQuery() from datetime import datetime, timedelta query.start_time = datetime.now() - timedelta(days=1) my_shipday.OrderService.query(query=query) ``` -------------------------------- ### Get Pickup Data as Dictionary Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/pickup.md Converts Pickup object data into a dictionary format suitable for API requests. Includes restaurant name, address, phone, and optional coordinates. ```python pickup = Pickup( name='Downtown Restaurant', phone_number='+1-555-0456', address=Address(...) ) body = pickup.get_body() print(body) ``` -------------------------------- ### Comprehensive Order Creation Error Handling Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/errors.md Handle various ShipdayException types during order creation, including specific validation errors for fields like 'order_number', 'customer', and 'pickup'. This example also catches general API errors and rate limiting exceptions. ```python from shipday import Shipday from shipday.order import Order, Address, Customer, Pickup, OrderItem from shipday.exceptions import ShipdayException, ShipdayRateLimitException my_shipday = Shipday(api_key='your_api_key') def create_and_submit_order(order_data): try: # Create order object order = Order(orderNumber=order_data['number']) # Validate order structure order.verify() # Submit to API response = my_shipday.OrderService.insert_order(order) return response except ShipdayException as e: error_msg = str(e) if 'order_number' in error_msg.lower(): print("Error: Order number is required") elif 'customer' in error_msg.lower(): print("Error: Customer information is incomplete") elif 'pickup' in error_msg.lower(): print("Error: Pickup location is incomplete") elif 'errorCode' in error_msg: print(f"API Error: {error_msg}") else: print(f"Unexpected error: {error_msg}") return None except ShipdayRateLimitException: print("Rate limited - please retry after a delay") return None ``` -------------------------------- ### Initialize Shipday Client and Access Services Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/shipday.md Demonstrates how to initialize the Shipday client with an API key and subsequently access its various service modules like CarrierService, OrderService, and OnDemandDeliveryService. ```python from shipday import Shipday # Initialize client with API key api_key = 'your_api_key_here' my_shipday = Shipday(api_key=api_key) # Access services carriers = my_shipday.CarrierService.get_carriers() orders = my_shipday.OrderService.get_orders() services = my_shipday.OnDemandDeliveryService.get_services() ``` -------------------------------- ### Initialize Shipday with Environment Variable Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/INDEX.md Configure the Shipday client by retrieving the API key from an environment variable. ```python import os api_key = os.getenv('SHIPDAY_API_KEY') my_shipday = Shipday(api_key=api_key) ``` -------------------------------- ### Get Delivery Details Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/on_demand_delivery_service.md Retrieves the current delivery details and tracking information for an assigned order. ```APIDOC ## get_details ### Description Retrieves delivery details and tracking information for an assigned order. ### Method GET ### Endpoint /on_demand_delivery/details/{order_id} ### Parameters #### Path Parameters - **order_id** (int) - Required - ID of the assigned order #### Query Parameters None #### Request Body None ### Request Example GET /on_demand_delivery/details/1234 ### Response #### Success Response (200) - **dict** - Dictionary with delivery details including tracking status, driver info, ETA #### Response Example ```json { "delivery_id": "d-12345", "status": "in_progress", "driver_name": "John Doe", "estimated_time": "2023-10-27T10:30:00Z", "tracking_url": "https://example.com/track/d-12345" } ``` ``` -------------------------------- ### Create and Use Address Objects Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates creating Address objects with complete and minimal information, accessing formatted addresses, and modifying address components. Use this for managing delivery or pickup locations. ```python from shipday.order import Address # Create address with all components delivery_address = Address( unit='Suite 100', street='555 Market Street', city='San Francisco', state='California', zip='94105', country='USA', latitude=37.7914, longitude=-122.3975 ) # Access formatted versions print(delivery_address.get_single_line()) # Single line format breakdown = delivery_address.get_breakdown() # Dictionary format print(breakdown) # Modify address delivery_address.unit = 'Floor 5' delivery_address.unit_in_address = True # Create address from minimal info simple_address = Address( street='123 Main Street', city='New York', country='USA' ) print(simple_address.get_single_line()) # Output: "123 Main Street, New York, USA" ``` -------------------------------- ### Configuration Pattern with Defaults Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md A pattern for initializing the Shipday client using environment variables for both the API key and timeout, providing default values. ```python import os from shipday import Shipday def initialize_shipday(): api_key = os.getenv('SHIPDAY_API_KEY') timeout = int(os.getenv('SHIPDAY_TIMEOUT', '1000')) if not api_key: raise ValueError("SHIPDAY_API_KEY not configured") return Shipday(api_key=api_key, timeout=timeout) my_shipday = initialize_shipday() ``` -------------------------------- ### Get Assigned Order Details Source: https://github.com/shipday/shipday-python-sdk/blob/main/README.md Use get_details() to retrieve the details of an order after it has been assigned to a service. Requires the order ID. ```python my_shipday.OnDemandDeliveryService.get_details(order_id=1234) ``` -------------------------------- ### Initialize Shipday Client Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md Initializes the Shipday client using API key and timeout from environment variables. Includes validation for the API key. ```python import os from shipday import Shipday from shipday.exceptions import ShipdayException def setup_shipday(): # Get configuration from environment api_key = os.getenv('SHIPDAY_API_KEY') timeout = int(os.getenv('SHIPDAY_TIMEOUT', '5000')) # Validate API key if not api_key or len(api_key) < 10: raise ValueError("Invalid or missing SHIPDAY_API_KEY") # Initialize client try: client = Shipday(api_key=api_key, timeout=timeout) print(f"✓ Connected to Shipday API") return client except ShipdayException as e: print(f"✗ Failed to initialize Shipday: {e}") raise # Use the client if __name__ == '__main__': my_shipday = setup_shipday() # Test connection by fetching orders try: orders = my_shipday.OrderService.get_orders() print(f"✓ Retrieved {len(orders)} orders") except Exception as e: print(f"✗ Error: {e}") ``` -------------------------------- ### Get All On-Demand Delivery Services Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/on_demand_delivery_service.md Retrieves a list of all configured on-demand delivery services. Useful for understanding all available options. ```python from shipday import Shipday my_shipday = Shipday(api_key='your_api_key') services = my_shipday.OnDemandDeliveryService.get_services() for service in services: print(f"Service: {service.get('name')}") ``` -------------------------------- ### Get All Carriers Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/carrier_service.md Retrieves a list of all carriers associated with your Shipday account. Useful for displaying carrier information or for use in other operations. ```python from shipday import Shipday my_shipday = Shipday(api_key='your_api_key') carriers = my_shipday.CarrierService.get_carriers() for carrier in carriers: print(f"Carrier: {carrier['name']}") ``` -------------------------------- ### Create and Submit a New Order Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md This snippet demonstrates the complete process of creating a new order object, populating it with customer and pickup information, order items, cost details, and delivery times, and then submitting it to Shipday. Ensure you replace 'your_api_key' with your actual Shipday API key. ```python from shipday import Shipday from shipday.order import Address, Customer, Pickup, OrderItem, Order, OrderCost from datetime import datetime, timedelta my_shipday = Shipday(api_key='your_api_key') # Create new order new_order = Order(orderNumber='100') # Set customer details new_order.customer = Customer( name='Jane Smith', email='jane@example.com', phone_number='+1-555-0123', address=Address( street='123 Main St', city='San Francisco', state='California', zip='94102', country='USA', latitude=37.7749, longitude=-122.4194 ) ) # Set pickup location new_order.pickup = Pickup( name='Downtown Restaurant', phone_number='+1-555-0456', address=Address( street='456 Market St', city='San Francisco', state='California', zip='94102', country='USA', latitude=37.7900, longitude=-122.3950 ) ) # Add items new_order.order_items = [ OrderItem(name='Caesar Salad', unit_price=12.99, quantity=1), OrderItem(name='Grilled Salmon', unit_price=24.99, quantity=1), OrderItem(name='Bottled Water', unit_price=3.00, quantity=2) ] # Set costs new_order.order_cost = OrderCost( tips=5.0, tax=5.50, discount=2.0, delivery_fee=4.99, total=60.96 ) # Set delivery times new_order.expected_pickup_time = datetime.now() + timedelta(minutes=15) new_order.expected_delivery_time = datetime.now() + timedelta(minutes=45) # Add special instructions new_order.delivery_instruction = "Leave at door, ring bell" new_order.pickup_instruction = "Order under Smith" # Submit order response = my_shipday.OrderService.insert_order(new_order) print(f"Order created with ID: {response.get('id')}") ``` -------------------------------- ### Cancel Delivery Assignment Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/on_demand_delivery_service.md Cancels a delivery assignment for an order. Note that cancellation is not guaranteed to succeed if the delivery has already started. ```APIDOC ## cancel ### Description Cancels a delivery assignment. ### Method POST ### Endpoint /on_demand_delivery/cancel ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **order_id** (int) - Required - ID of the assigned order to cancel ### Request Example ```json { "order_id": 1234 } ``` ### Response #### Success Response (200) - **dict** - Response object confirming the cancellation attempt #### Response Example ```json { "delivery_id": "d-12345", "status": "cancelled" } ``` ``` -------------------------------- ### Setting Address Unit Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates how to set the unit/apartment number for an address instance. This property is readable and writable. ```python address.unit = 'Apt 5B' ``` -------------------------------- ### Get Order by Number Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_service.md Retrieves orders that match a specific order number. Use this when you need to find a particular order by its identifier. ```python from shipday import Shipday my_shipday = Shipday(api_key='your_api_key') orders = my_shipday.OrderService.get_order(order_number='100') if orders: print(f"Found {len(orders)} order(s) with number 100") ``` -------------------------------- ### Setting Pickup Instructions Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Demonstrates setting and retrieving special pickup instructions for an Order. The pickup_instruction attribute must be a string or None. ```python order.pickup_instruction = "Ask for John" instr = order.pickup_instruction ``` -------------------------------- ### Initialize Shipday Client Source: https://github.com/shipday/shipday-python-sdk/blob/main/README.md Initialize the Shipday client with your API key. Obtain your API key from the Shipday Dispatch Dashboard integrations tab. ```python API_KEY = '##########.#######################' my_shipday = Shipday(api_key=API_KEY) ``` -------------------------------- ### CarrierRequest Class Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/carrier_request.md Represents a carrier/driver with contact information. It allows setting and getting the carrier's name, email, and phone number. ```APIDOC ## Class: CarrierRequest ### Description Represents a carrier/driver with contact information. It allows setting and getting the carrier's name, email, and phone number. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (str) - Required (for submission) - Carrier's full name - **email** (str) - Required (for submission) - Carrier's email address - **phone_number** (str) - Required (for submission) - Carrier's phone number ### Instance Properties #### name (str) Carrier's full name. Readable and writable. #### email (str) Carrier's email address. Readable and writable. #### phone_number (str) Carrier's phone number. Readable and writable. ``` -------------------------------- ### Setting Address ZIP Code Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates how to set the postal or ZIP code for an address instance. This property is readable and writable. ```python address.zip = '94102' ``` -------------------------------- ### Getting Single-Line Address String Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Generates a formatted single-line string representation of the address. The inclusion of the unit number is controlled by the `unit_in_address` flag. ```python address = Address( street='123 Main St', unit='Apt 5B', city='San Francisco', state='CA', zip='94102', country='USA' ) # Without unit in address address.unit_in_address = False print(address.get_single_line()) # Output: "123 Main St, San Francisco, CA, 94102, USA" # With unit in address address.unit_in_address = True print(address.get_single_line()) # Output: "123 Main St, Apt 5B, San Francisco, CA, 94102, USA" ``` -------------------------------- ### Import Order Data Models Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/INDEX.md Import data models for creating and managing orders. ```python from shipday.order import ( Order, Address, Customer, Pickup, OrderItem, OrderCost, OrderQuery, OrderStatus, CardType ) ``` -------------------------------- ### Order Class Initialization Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Represents a complete order with customer details, pickup location, items, and costs. Use this to initialize a new order object. ```python class Order: def __init__(self, order_number: str = None, customer: Customer = None, pickup: Pickup = None, order_items: List[OrderItem] = None, order_cost: OrderCost = None, expected_delivery_time: datetime = None, expected_pickup_time: datetime = None, **kwargs) -> None ``` -------------------------------- ### Get Active On-Demand Delivery Services Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/on_demand_delivery_service.md Retrieves only the currently active and enabled on-demand delivery services. Useful for filtering down to usable providers. ```python from shipday import Shipday my_shipday = Shipday(api_key='your_api_key') active_services = my_shipday.OnDemandDeliveryService.get_active_services() print(f"Active services: {', '.join(active_services)}") ``` -------------------------------- ### Setting OrderQuery end_cursor Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_query.md Sets or gets the pagination end cursor for the order query. This property is readable and writable and must be an integer or None. ```python query.end_cursor = 100 cursor = query.end_cursor ``` -------------------------------- ### Import Shipday Class Source: https://github.com/shipday/shipday-python-sdk/blob/main/README.md Import the main Shipday class from the shipday package to begin using the SDK. ```python from shipday import Shipday ``` -------------------------------- ### Setting OrderQuery end_time Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_query.md Sets or gets the end time for the order query. This property is readable and writable and must be a datetime object or None. ```python query.end_time = datetime.now() end = query.end_time ``` -------------------------------- ### Setting Address Street Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates how to set the street address for an address instance. This property is readable and writable. ```python address.street = '123 Main Street' ``` -------------------------------- ### Access and Modify Pickup Address Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/pickup.md Shows how to assign and get the Address object for a pickup location. The address must be an instance of the Address class. ```python pickup.address = Address(...) addr = pickup.address ``` -------------------------------- ### Initialize CarrierService Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/carrier_service.md Initializes the CarrierService with your Shipday API key for authentication. ```python from shipday import Shipday my_shipday = Shipday(api_key='your_api_key') ``` -------------------------------- ### Shipday Client Initialization Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/shipday.md Initializes the Shipday client with an API key and provides access to OrderService, CarrierService, and OnDemandDeliveryService. ```APIDOC ## Class: Shipday Initializes the Shipday client with an API key and instantiates all available services. ### Parameters #### Parameters - **api_key** (str) - Required - Shipday API key obtained from the Dispatch Dashboard. Must be at least 10 characters. ### Instance Attributes - **OrderService** (`shipday.services.OrderService`) - Service for managing orders - **CarrierService** (`shipday.services.CarrierService`) - Service for managing carriers/drivers - **OnDemandDeliveryService** (`shipday.services.OnDemandDeliveryService`) - Service for managing on-demand delivery integrations ### Raises - `ShipdayException` - If api_key is None or less than 10 characters ### Example ```python from shipday import Shipday # Initialize client with API key api_key = 'your_api_key_here' my_shipday = Shipday(api_key=api_key) # Access services carriers = my_shipday.CarrierService.get_carriers() orders = my_shipday.OrderService.get_orders() services = my_shipday.OnDemandDeliveryService.get_services() ``` ``` -------------------------------- ### Import Shipday Services Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/INDEX.md Import the necessary service classes from the Shipday SDK. ```python from shipday.services import OrderService, CarrierService, OnDemandDeliveryService ``` -------------------------------- ### OrderService Initialization Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_service.md Initializes the OrderService with your Shipday API key for authentication. ```APIDOC ## Class: OrderService ```python class OrderService: def __init__(self, api_key: str) -> None ``` Initializes the OrderService with authentication credentials. ### Constructor Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | api_key | str | Yes | — | Shipday API key for authentication | ``` -------------------------------- ### Setting Address Country Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates how to set the country name for an address instance. This property is readable and writable. ```python address.country = 'USA' ``` -------------------------------- ### Setting Address City Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates how to set the city name for an address instance. This property is readable and writable. ```python address.city = 'San Francisco' ``` -------------------------------- ### Setting OrderQuery order_status Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_query.md Sets or gets the order status filter for the query. This property is readable and writable and must be a valid OrderStatus value or None. ```python query.order_status = 'ACTIVE' status = query.order_status ``` -------------------------------- ### Get Carriers Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/carrier_service.md Retrieves a list of all carriers associated with your Shipday account. This method returns a list of dictionaries, where each dictionary contains information about a specific carrier. ```APIDOC ## GET /carriers ### Description Retrieves all carriers associated with your Shipday account. ### Method GET ### Endpoint /carriers ### Parameters None ### Request Example ```python from shipday import Shipday my_shipday = Shipday(api_key='your_api_key') carriers = my_shipday.CarrierService.get_carriers() for carrier in carriers: print(f"Carrier: {carrier['name']}") ``` ### Response #### Success Response (200) - **carriers** (list) - List of carrier dictionaries containing carrier information #### Response Example ```json [ { "id": 1, "name": "John Doe", "email": "john.doe@shipday.com", "phone_number": "+1-234-567-8900" } ] ``` ``` -------------------------------- ### OrderCost Class Initialization Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_cost.md Initializes an OrderCost object with default values for tips, tax, discount, delivery fee, and total. Accepts additional keyword arguments. ```python class OrderCost: def __init__(self, tips: float = 0.0, tax: float = 0.0, discount: float = 0.0, delivery_fee: float = 0.0, total: float = 0.0, **kwargs) -> None ``` -------------------------------- ### Setting Expected Pickup Time Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Illustrates setting the expected pickup time for an Order. Requires importing the datetime object. The attribute must be a datetime object or None. ```python order.expected_pickup_time = datetime.now() pickup_time = order.expected_pickup_time ``` -------------------------------- ### Example JSON Error Response Format Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md Details the format of JSON error responses from the Shipday API, providing an error code and a descriptive message. ```json { "errorCode": "INVALID_ORDER", "errorMessage": "Order number is required" } ``` -------------------------------- ### Initialize Shipday with Custom Timeout Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/INDEX.md Initialize the Shipday client with a custom request timeout value in milliseconds. ```python my_shipday = Shipday(api_key='your_api_key', timeout=5000) # 5 seconds ``` -------------------------------- ### Setting Delivery Instructions Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Shows how to set and retrieve special delivery instructions for an Order. The delivery_instruction attribute must be a string or None. ```python order.delivery_instruction = "Ring doorbell twice" instr = order.delivery_instruction ``` -------------------------------- ### Access Shipday Services Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/configuration.md After initializing the Shipday client, you can access the available services: OrderService, CarrierService, and OnDemandDeliveryService. ```python my_shipday = Shipday(api_key='your_api_key') # Access services order_service = my_shipday.OrderService carrier_service = my_shipday.CarrierService delivery_service = my_shipday.OnDemandDeliveryService ``` -------------------------------- ### Accessing and Setting Customer Information Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Shows how to assign and retrieve customer details for an Order. The customer attribute must be an instance of the Customer class. ```python order.customer = Customer(...) customer = order.customer ``` -------------------------------- ### Getting OrderQuery Body for API Request Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_query.md Converts the OrderQuery object into a dictionary format suitable for API requests. Only fields that have been populated are included in the output dictionary. ```python from shipday.order import OrderQuery from datetime import datetime, timedelta query = OrderQuery( start_time=datetime.now() - timedelta(days=7), order_status='ACTIVE' ) body = query.get_body() print(body) ``` -------------------------------- ### Get Carrier API Request Body Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/carrier_request.md Generates a dictionary representation of the carrier data suitable for API requests. This method automatically calls verify() first. ```python from shipday.carrier import CarrierRequest carrier = CarrierRequest( name='Alice Johnson', email='alice@example.com', phone_number='+1-415-555-0199' ) body = carrier.get_body() print(body) # Returns: {'name': 'Alice Johnson', 'phoneNumber': '+1-415-555-0199', 'email': 'alice@example.com'} ``` -------------------------------- ### Setting Address State Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates how to set the state or province for an address instance. This property is readable and writable. ```python address.state = 'California' ``` -------------------------------- ### Pickup Class Initialization Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/pickup.md Initializes a Pickup object with name, address, and phone number. Supports additional keyword arguments. ```python class Pickup: def __init__(self, name: str = None, address: Address = None, phone_number: str = None, **kwargs) -> None ``` -------------------------------- ### Get Delivery Details and Tracking Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/on_demand_delivery_service.md Retrieves the current delivery status and tracking information for an order that has been assigned to a service provider. Includes driver details and estimated time of arrival. ```python from shipday import Shipday my_shipday = Shipday(api_key='your_api_key') # Get delivery tracking details details = my_shipday.OnDemandDeliveryService.get_details(order_id=1234) print(f"Delivery status: {details.get('status')}") print(f"Driver: {details.get('driver_name')}") print(f"ETA: {details.get('estimated_time')}") ``` -------------------------------- ### Get Order Body for API Submission Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Returns the complete order as a dictionary in the API request format. Use this method to prepare the order payload for submission to the Shipday API. ```python order = Order(orderNumber='100') # ... set customer, pickup, items, cost ... api_payload = order.get_body() print(api_payload) ``` -------------------------------- ### get_body Method Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_cost.md Returns the cost data as a dictionary formatted for API requests. The dictionary includes keys for tips, tax, discount, delivery fee, and total cost. ```APIDOC ## Method: get_body Returns cost data as a dictionary in API request format. ### Returns | Type | Description | |------|-------------| | `dict` | Dictionary with keys: tips, tax, discountAmount, deliveryFee, totalCost, totalOrderCost | ### Example ```python cost = OrderCost( tips=5.0, tax=8.50, discount=2.0, delivery_fee=4.99, total=65.49 ) body = cost.get_body() print(body) # Returns: {'tips': 5.0, 'tax': 8.5, 'discountAmount': 2.0, 'deliveryFee': 4.99, 'totalCost': 65.49, 'totalOrderCost': 65.49} ``` ``` -------------------------------- ### OrderQuery Initialization Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_query.md Initializes an OrderQuery object with optional parameters for filtering orders by time range, status, and pagination. ```python class OrderQuery: def __init__(self, start_time: datetime = None, end_time: datetime = None, order_status: str = None, start_cursor: int = None, end_cursor: int = None, **kwargs) -> None ``` -------------------------------- ### Getting OrderCost as Dictionary Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_cost.md Converts the OrderCost object into a dictionary format suitable for API requests. Includes keys like 'tips', 'tax', 'discountAmount', 'deliveryFee', 'totalCost', and 'totalOrderCost'. ```python cost = OrderCost( tips=5.0, tax=8.50, discount=2.0, delivery_fee=4.99, total=65.49 ) body = cost.get_body() print(body) # Returns: {'tips': 5.0, 'tax': 8.5, 'discountAmount': 2.0, 'deliveryFee': 4.99, 'totalCost': 65.49, 'totalOrderCost': 65.49} ``` -------------------------------- ### Setting Expected Delivery Time Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Demonstrates setting the expected delivery time for an Order. Requires importing the datetime object. The attribute must be a datetime object or None. ```python from datetime import datetime order.expected_delivery_time = datetime.now() delivery_time = order.expected_delivery_time ``` -------------------------------- ### Address Class Initialization Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Initializes an Address object with various components like unit, street, city, state, zip, country, and optional GPS coordinates. All parameters are optional. ```python class Address: def __init__(self, unit: str = None, street: str = None, city: str = None, state: str = None, zip: str = None, country: str = None, latitude: float = None, longitude: float = None, **kwargs) -> None ``` -------------------------------- ### Getting OrderItem Body for API Request Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_item.md Demonstrates how to use the get_body method to retrieve the OrderItem data in a dictionary format suitable for API requests. This includes optional fields like 'detail'. ```python item = OrderItem( name='Grilled Salmon', unit_price=24.99, quantity=1, detail='Medium-rare, sauce on side' ) body = item.get_body() # Returns: {'name': 'Grilled Salmon', 'unitPrice': 24.99, 'quantity': 1, 'detail': '...'} ``` -------------------------------- ### get_body Method Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/pickup.md Returns the pickup data formatted as a dictionary suitable for API requests. This includes details like restaurant name, address, and phone number. ```APIDOC ## Method: get_body ```python def get_body(self) -> dict ``` Returns pickup data as a dictionary in API request format. ### Returns | Type | Description | |------|-------------| | `dict` | Dictionary with keys: restaurantName, restaurantAddress, pickup (address breakdown), restaurantPhoneNumber (if available), pickupLatitude (if available), pickupLongitude (if available) | ### Example ```python pickup = Pickup( name='Downtown Restaurant', phone_number='+1-555-0456', address=Address(...) ) body = pickup.get_body() print(body) ``` ``` -------------------------------- ### get_services() Source: https://github.com/shipday/shipday-python-sdk/blob/main/README.md Retrieves general information on On-Demand Delivery Services. ```APIDOC ## get_services() ### Description Retrieves general information on On-Demand Delivery Services. ### Method N/A (SDK method) ### Endpoint N/A (SDK method) ### Parameters None ### Request Example ```python my_shipday.OnDemandDeliveryService.get_services() ``` ### Response (Details not provided in source) ``` -------------------------------- ### Accessing and Modifying OrderItem Properties Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order_item.md Demonstrates how to read and write properties of an OrderItem instance. ```python item.name = 'Pepperoni Pizza' name = item.name ``` ```python item.unit_price = 15.99 price = item.unit_price ``` ```python item.quantity = 2 qty = item.quantity ``` ```python item.add_ons = 'Extra cheese, no onions' ``` ```python item.detail = 'Gluten-free crust' ``` -------------------------------- ### Handle Invalid API Key Initialization Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/errors.md Catch ShipdayException during initialization if an invalid API key is provided. This ensures your application doesn't proceed with incorrect credentials. ```python from shipday import Shipday from shipday.exceptions import ShipdayException try: my_shipday = Shipday(api_key='invalid') except ShipdayException as e: print(f"Failed to initialize: {e}") # Handle error: verify API key configuration ``` -------------------------------- ### Setting Address Latitude Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates how to set the GPS latitude coordinate for an address instance. This property is readable and writable and must be paired with longitude. ```python address.latitude = 37.7749 ``` -------------------------------- ### Setting Address Longitude Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/address.md Demonstrates how to set the GPS longitude coordinate for an address instance. This property is readable and writable and must be paired with latitude. ```python address.longitude = -122.4194 ``` -------------------------------- ### Import ShipdayRateLimitException Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/errors.md Import the ShipdayRateLimitException for specific handling of rate limiting errors. ```python from shipday.exceptions import ShipdayRateLimitException ``` -------------------------------- ### Handle General and Rate Limit Exceptions Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/INDEX.md Demonstrates catching ShipdayException and the more specific ShipdayRateLimitException. The rate limit exception is raised on HTTP 429 responses. ```python from shipday.exceptions import ShipdayException, ShipdayRateLimitException try: my_shipday = Shipday(api_key='invalid') except ShipdayException as e: pass try: orders = my_shipday.OrderService.get_orders() except ShipdayRateLimitException as e: # Raised on HTTP 429 pass ``` -------------------------------- ### Access and Modify Pickup Name Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/pickup.md Demonstrates how to set and retrieve the name of a pickup location. The name must be a string. ```python pickup.name = 'Downtown Pizzeria' name = pickup.name ``` -------------------------------- ### get_body Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/order.md Returns the complete order as a dictionary in the API request format. ```APIDOC ## Method: get_body Returns the complete order as a dictionary in the API request format. ### Returns | Type | Description | |------|-------------| | `dict` | Order object ready for API submission | ### Example ```python order = Order(orderNumber='100') # ... set customer, pickup, items, cost ... api_payload = order.get_body() print(api_payload) ``` ``` -------------------------------- ### get_body Method Source: https://github.com/shipday/shipday-python-sdk/blob/main/_autodocs/api-reference/customer.md Returns the customer data formatted as a dictionary suitable for API requests. ```APIDOC ## Method: get_body ```python def get_body(self) -> dict ``` Returns customer data as a dictionary in API request format. ### Returns | Type | Description | |------|-------------| | `dict` | Dictionary with keys: customerName, customerAddress, dropoff (address breakdown), customerEmail, customerPhoneNumber, deliveryLatitude (if available), deliveryLongitude (if available) | ### Example ```python customer = Customer( name='Jane Smith', email='jane@example.com', phone_number='+1-555-0123', address=Address(...) ) body = customer.get_body() print(body) ``` ```