Address & location validation
- Address input exclusivity:
- An error is raised if you provide both
pickupAddressandpickupPlaceId(or the dropoff equivalents). You must use one or the other. - An error is raised if you provide address components (e.g.,
pickupAddressFormattedStreet) along withpickupAddressorpickupPlaceId.
- An error is raised if you provide both
- Address input requirement: If no store location ID is provided, it requires one of the following for both pickup and dropoff:
- A single-line address string (
pickupAddress/dropoffAddress). - A Google Place ID (
pickupPlaceId/dropoffPlaceId). - A set of address components (street, city, zip, etc.).
- If none of these are present, a “required field” error is added for the address.
- A single-line address string (
- Store location logic:
- If a
pickupStoreLocationIdorpickupExternalStoreLocationIdis provided, it attempts to find the corresponding store location. - Existence check: It fails if the store location ID does not exist for that organization or if the store has been deleted.
- Automatic store creation: If an external store location ID is given but not found, it checks an organization preference for automatically creating store locations. If enabled, it attempts to create a new store location using the order’s pickup details.
- Default field population: If a valid pickup store location is found, it automatically populates the order’s pickup fields (name, phone, email, instructions) with the data from the store, unless those fields were already provided in the request.
- If a
- Geocoding and parsing:
- If a raw
pickupAddressordropoffAddressstring is provided, it attempts to parse it and geocode it to get coordinates (latitude/longitude). It will raise an error if parsing fails (e.g., “Address not found”). - It performs the same parsing and geocoding for
pickupPlaceIdanddropoffPlaceId.
- If a raw
- Identical location check:
- It checks if the
pickupPlaceIdanddropoffPlaceIdare the same. If so, it raises an error. - After parsing, it compares the final parsed pickup and dropoff address components. If they are identical, it raises an error.
- It checks if the
- Cross-country check: Fails if the parsed
pickupAddressCountryanddropoffAddressCountryare not the same. - Distance check:
- Calculates the straight-line distance between the pickup and dropoff coordinates.
- It checks against an organization-specific maximum delivery distance preference and fails if the distance exceeds it.
Required & conditional fields
- Core required fields: Checks that a value is present for:
valueCents,pickupPhoneNumber,dropoffPhoneNumber,deliveryMode. - Contact name requirement:
- Requires either
pickupFirstNameorpickupBusinessNameto be present. - Requires either
dropoffFirstNameordropoffBusinessNameto be present.
- Requires either
Data type & format validation
- Integer fields: Verifies that
valueCents,tipAmountCents, anditemsCountare valid integers. - Float/decimal fields: Verifies that dimensional fields (
weight,height,width,depth,volume) are valid decimal numbers and are greater than 0. - Order value: Checks that
valueCentsis greater than 0. - Item count: Checks that
itemsCount, if provided, is at least 1. - Name fields: Checks that all name fields (
pickupFirstName, etc.) are strings and do not exceed a maximum length (80 characters). - Phone numbers:
- Checks that
pickupPhoneNumberanddropoffPhoneNumberare valid phone numbers for the corresponding country. - If the number is invalid but the organization has a default backup phone number configured, it will use the backup number instead of failing.
- Checks that
- Items: If the
itemsfield is provided, it validates that each entry in the list is a valid item structure. - Order metadata:
- It validates that the dictionary has no more than 15 key-value pairs and that all values are simple scalar types (string, int, float, bool).
Enum & ID validation
- Delivery mode:
- Ensures
deliveryModeis one of the allowed values (noworscheduled). - If mode is
now, it nullifies all datetime fields. - If mode is
scheduled, it requires at least one of the datetime fields (pickupStartTime, etc.) to be set.
- Ensures
- Currency:
- If a
currencyis provided, it ensures it’s in the list of supported currencies. - If no currency is provided, it attempts to infer it from the
pickupAddressCountry.
- If a
- Requirements: Ensures all provided
requirementsare supported (see Order Requirements), unless it’s acustom:requirement. - Vehicle size: Ensures
minimumVehicleSizeis one of the supported vehicle sizes. - Dispatch strategy: If
dispatchStrategyIdis provided, it confirms that it exists, belongs to the organization, and is not deleted. - Delivery window: If
deliveryWindowIdis provided, it checks if it’s a valid, active window. - External ID uniqueness: If an
externalIdis given, it ensures no other order within the same organization already uses that ID.
Datetime validation
- Parsing: Attempts to parse all provided datetime strings (
pickupStartTime,pickupEndTime,dropoffStartTime,dropoffEndTime) into proper datetime objects. It can handle UTC or timezone-localized inputs based on an order flag. Fails if a string is not a valid date format. - Chronological order:
pickupStartTimemust be earlier thanpickupEndTime.dropoffStartTimemust be earlier thandropoffEndTime.pickupStartTimemust be earlier thandropoffEndTime.pickupEndTimemust be earlier thandropoffEndTime.