Product API
Fulfillment guide
Send Order
Create Direct Order

Create a delivery order

POST api.foodin.ai/users/{user_id}/orders/direct

Creates a direct delivery order for the reserved time slot. If the reservation has expired, Foodin still attempts to book the time slot. If, however, the time slot capacity is filled, your site needs to prompt the customer to select another time slot.

Request

Parameters

FieldTypeDescription
user_idstringThe ID of the user.

Order parameters

FieldTypeDescription
order_idstringThe unique store-generated order ID to use for the order. The ID can be used later for lookup.
location_codestringLocation code of the store where the delivery driver picks up the order.
localestringThe order's locale in IETF Language Tag format. Example: en-US.
start_atstringThe requested delivery window start time in ISO 8601 format.
end_atstringThe requested delivery window end time in ISO 8601 format.
service_option_hold_idintegerThe ID of the service option hold.
first_namestringThe user's first name.
last_namestringThe user's last name.
user_phonestringThe user's phone number.
initial_tip_centsintegerThe pre-delivery tip in cents.
items_countintegerThe number of items in the order.
bags_countintegerThe number of bags in the order.
items_weightnumberThe weight of the items in lbs.
cart_totalnumberThe gross merchandise value (gmv) of the cart in dollar amount.
bag_labelstringA user-friendly label that helps shoppers identify the order.
alcoholicbooleanIndicates whether the order contains alcohol. Defaults to false.
leave_unattendedbooleanIndicates whether the user wants the driver to leave the order unattended. Defaults to false.
special_instructionsstringSpecial instructions about the order to pass on to the shopper.
customer_sms_opt_outbooleanIndicator whether the user has opted-out from receiving SMS communication. Defaults to false.
with_handoff_timebooleanIndicator whether the handoff time is calculated during order creation. Defaults to false.
addressObjectThe address of the user.

Address Object

FieldTypeDescription
address_line_1stringThe first address line.
address_line_2stringThe second address line.
address_typestringThe type of address, e.g., "residential".
postal_codestringThe postal/zip code of the address.

To define a valid start_at and end_at delivery window, the following set of conditions must all be true:

  • At least one of the start_at or the end_at is within the service option window.
  • The start_at is within 2 hours of the service option start time.
  • The end_at is within 2 hours of the service option end time.

For example, if the service option window is 14:00-16:00, then the following request windows are valid: 13:30-14:30, 14:00-15:00, 14:30-15:30, 15:00-16:00, or 15:30-16:30. The following request windows are invalid: 12:00-13:59, 13:00-17:00, 11:00-15:00, or 15:00-19:00.

Request examples

const request = require("request");
 
const options = {
    method: "POST",
    url: "https://api.foodin.ai/users/{user_id}/orders/direct",
    headers: {
        Accept: "application/json",
        Authorization: "Bearer <token>",
        "Content-Type": "application/json"
    },
    data: {
    order_id: "string",
    location_code: "string",
    locale: "string",
    start_at: "string",
    end_at: "string",
    service_option_hold_id: 1,
    first_name: "string",
    last_name: "string",
    user_phone: "string",
    initial_tip_cents: 1,
    items_count: 1,
    bags_count: 1,
    items_weight: 1,
    cart_total: 1,
    bag_label: "string",
    alcoholic: true,
    leave_unattended: true,
    special_instructions: "string",
    customer_sms_opt_out: true,
    with_handoff_time: true,
    address: {
      address_line_1: "string",
      address_line_2: "string",
      address_type: "string",
      postal_code: "string",
    },  ]
}
};
 
request(options, function(error, response, body) {
    if (error) throw new Error(error);
    console.log(body);
});

Response

Order

FieldTypeDescription
idstringThe ID of the order.
statusstringThe current order status.
order_urlstringLink to view the order.
created_atstringThe time of order creation in ISO 8601 format.
cancellation_reasonstringThe reason the order was canceled.
localestringThe order's locale in POSIX format. Example: en_US.
fulfillment_detailsObjectThe order delivery details.

Fullfilment_details Object

FieldTypeDescription
store_locationstringThe location code of the store where the order was fulfilled. The store_location is often the same as the location_code that was used to create the order. However, orders can be fulfilled from a different store location.
Window_starts_atstringThe start time of the delivery window in ISO 8601 format.
Window_ends_atstringThe end time of the delivery window in ISO 8601 format.
Delivered_atstringThe time the order was delivered in ISO 8601 format.
Bag_countintegerThe number of bags in the order.
Handoff_window_starts_atstringThe start time of the handoff window in ISO 8601 format.
Handoff_window_ends_atstringThe end time of the handoff window in ISO 8601 format.

Response examples

200 Order created
{
  "id": "12345676789012345678780",
  "status": "created",
  "order_url": "https://foodin.ai/example_store/example-order",
  "created_at": "2058-02-22T00:00:00Z",
  "cancellation_reason": "shopper_driven",
  "locale": "en_US",
  "fulfillment_details": {
    "window_starts_at": "2058-02-22T00:00:00Z",
    "window_ends_at": "2058-02-22T00:30:00Z"
  },
  "handoff_time": "2058-02-22T00:30:00Z",
  "is_fallback_window": false
}

4XX Errors

CodeCauseError Message
400Invalid postal code"not found"
400Unsupported postal code"not supported"
400Handoff time is requested but not configured"Handoff time calculation is not configured for this store."
400Expired ETA option hold"ETA option hold has expired."
400User without phone number"can't be blank"
400Invalid order params*"There were issues with your request"
400Fails alcohol compliance check"Alcoholic items can not be added to this order. Please remove and retry."
400Order id already exists"Order already in use."
400Invalid start at/end at"Invalid start / end at."
400Invalid first name"First name is invalid"
400Request could not be processed at this time"The request could not be completed at this time, try again later."
400Missing or invalid address"Required parameter missing or invalid"
400Invalid address"invalid_address"
400Location not available for delivery"Specified store is not available for delivery."
400Service option is no longer available"The delivery time you selected is no longer available - please select another time"
400Address contains PO box"address contains PO Box"
400Invalid service option hold"Hold not found"
400Tip over maximum"Tip value is above maximum: $500.00."
403Inactive user"User Not Active"
404Order not found"Resource not found"
423The target resource is locked"The target resource is locked."