1.0.1 • Published 2 years ago

extra-chicken v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Extra Chicken - An unofficial Chipotle API wrapper

Extra chicken is an unofficial Chipotle API wrapper that allows you to programatically interact with the Chipotle website to view stores, menus, place orders, and more.

Table of Contents

Installation

Usage Examples

API Documentation

Installation

npm install extra-chicken

Usage Examples

Initialize Chipotle Object

import Chipotle from 'extra-chicken' 

// creates a non-headless puppeteer instance that logs into the Chipotle site with the specified credentials
const chip = await Chipotle.create("account-email@gmail.com", "account-password", false)

Fetch the closest restaurant and get its menu

lat = 0 
long = 0
proximity = 10000
restaurants = await chip.searchRestaurants(lat, long, proximity)
const closestRestaurant = restaurants[0]
const menu = await chip.getRestaurantMenu(closestRestaurant.restaurantNumber)

Add Cart Items and Checkout

Notes about the cart and checkout process

  • Chipotle checkout requires the use of a saved credit card. Make sure you have a credit card saved on your Chipotle account if you plan to use automated checkout.
  • Chipotle carts use ETags which are returned in a header with every cart related action. All cart/order related methods will return an array with the first element being the data and the second element is the ETag required to continue modifying the cart.
const restaurantId = 3171
const [order, eTag] = await chip.createOrder(restaurantId) 
const [atcResponse, eTag2] = await chip.addItemToCart(
    order.orderId, 
    eTag, 
    "test", 
    [{ 
       "menuItemId":"CMG-101",
		"menuItemName":"Chicken Bowl",
		"quantity":1,
		"contents":[
		   {
			  "menuItemId":"CMG-5101",
			  "menuItemName":"Fajita Veggies",
			  "quantity":1,
			  "isUpSell":false,
			  "customizationId":2
		   },
		   {
			  "menuItemId":"CMG-5002",
			  "menuItemName":"Brown Rice",
			  "quantity":1,
			  "isUpSell":false,
			  "customizationId":2
		   },
		   {
			  "menuItemId":"CMG-5051",
			  "menuItemName":"Black Beans",
			  "quantity":1,
			  "isUpSell":false,
			  "customizationId":2
		   }
    }] as CreateOrderEntree[],
    [{
      "menuItemId": "CMG-4025",
		"menuItemName": "Tortilla on the Side",
		"quantity": 1,
		"isUpSell": false
    }] as CreateOrderContent[],
    [{
        "menuItemId":"CMG-2019",
        "menuItemName":"22 fl oz Tractor Organic Watermelon Limeade",
        "quantity":1,
        "isUpSell":false
    }] as CreateOrderContent[]
)
const [addUtensilsResponse, eTag3] = await chip.addUtensilsToOrder(order.orderId, eTag2)
// set the browser's stored order 
await chip.changeStoredOrder(eTag3, addUtensilsResponse.order) 

// poll pickup times 
const pickupTimes = await chip.getRestaurantPickupTimes(restaurantId)
// checkout order and pickup ASAP and pay with the card ending in 5432
const orderResult = await chip.browserCheckout(pickupTimes[0], "5432") 

API Documentation

Chipotle

The class representing the Chipotle API wrapper.

Kind: global class

chipotle.getToken() ⇒ string

Gets the JWT token associated with the object.

Kind: instance method of Chipotle
Returns: string - The JWT token.

chipotle.setUserAgent(userAgent)

Sets the browser's user agent.

Kind: instance method of Chipotle

ParamTypeDescription
userAgentstringThe user agent.

chipotle.searchRestaurants(latitude, longitude, searchRadius) ⇒ Array<Restaurant>

Searches for Chipotles near a lat long.

Kind: instance method of Chipotle
Returns: Array<Restaurant> - A list of restaurants near the location provided.

ParamTypeDescription
latitudenumberThe latitude of the location to search in.
longitudenumberThe longitude of the location to search in.
searchRadiusnumberThe search radius. Unknown unit. Might be feet?

chipotle.getRestaurantMenu(restaurantId) ⇒ GetMenuResponse

Gets a restaurant's menu.

Kind: instance method of Chipotle
Returns: GetMenuResponse - A response object containing the menu and store id.

ParamTypeDescription
restaurantIdnumberThe id number of the restaurant.

chipotle.createOrder(restaurantId) ⇒ Array<{order: Order, eTag: string}>

Creates an empty order.

Kind: instance method of Chipotle
Returns: Array<{order: Order, eTag: string}> - An order object as well as the associated ETag. The ETag is required to modify the order further (e.g. atc).

ParamTypeDescription
restaurantIdnumberThe id number of the desired restaurant.

chipotle.addItemToCart(orderId, eTag, mealName, entrees, sides, drinks) ⇒ Array<{addToOrderResponse: AddToOrderResponse, eTag: string}>

Adds item(s) to the specified cart.

Kind: instance method of Chipotle
Returns: Array<{addToOrderResponse: AddToOrderResponse, eTag: string}> - A response body containing the mealId, order contents, and swapped entrees. The second return value is the ETag.

ParamTypeDescription
orderIdstringThe target order id.
eTagstringThe most recent ETag associated with the order. This is returned from createOrder and all order related methods.
mealNamestringThe name of the meal. This is commonly the customers name.
entreesArray<CreateOrderEntree>An array of entrees to add to the order.
sidesArray<CreateOrderContent>An array of sides to add to the order.
drinksArray<CreateOrderContent>An array of drinks to add to the order.

chipotle.addUtensilsToOrder(orderId, eTag) ⇒ Array<{addUtensilsResponse: AddUtensilsResponse, ETag: string}>

Adds utensils to an order.

Kind: instance method of Chipotle
Returns: Array<{addUtensilsResponse: AddUtensilsResponse, ETag: string}> - A response body containing the utensil item id and the order body.

ParamTypeDescription
orderIdstringThe target order id.
eTagstringThe most recent ETag associated with the order. This is returned from createOrder and all order related methods.

chipotle.getWallet() ⇒ Array<Wallet>

Gets a list of saved payment methods.

Kind: instance method of Chipotle
Returns: Array<Wallet> - A list of saved payment methods.

chipotle.getRestaurantPickupTimes(restaurantId) ⇒ Array<string>

Gets a list of available pickup times at a specified restaurant.

Kind: instance method of Chipotle
Returns: Array<string> - An array of pickup times. The time is formatted YYYY-MM-DDTHH:MM:SS.

ParamTypeDescription
restaurantIdnumberThe id of the target restaurant.

chipotle.changeStoredOrder(eTag, order)

Changes the stored order data on the browser instance.

Kind: instance method of Chipotle

ParamTypeDescription
eTagstringThe most recent ETag associated with the order.
orderOrderThe order body to save.

chipotle.browserAtc(entree, drinks, sides, mealName, utensils)

Adds an entree + sides + drinks to cart using the browser. Not recommended to use over the changeStoredOrder and addItemToCart methods beucase it's prone to runtime errors and is slower than alternative methods.

Kind: instance method of Chipotle

ParamTypeDescription
entreeCreateOrderEntreeThe entree object to add.
drinksArray<CreateOrderContent>An array of drink objects to add.
sidesArray<CreateOrderContent>An array of side objects to add.
mealNamestringThe name of the meal. Typically the customer's name.
utensilsbooleanWhether to add utensils to the order.

chipotle.browserCheckout(pickupTime, cardLastFour) ⇒ string | Array<CheckoutError>

Checks out the browser instance's current cart.

Kind: instance method of Chipotle
Returns: string | Array<CheckoutError> - An array of checkout errors or a success message.

ParamTypeDescription
pickupTimestringThe order pickup time. This should be in the same format returned in getRestaurantPickupTimes (YYYY-MM-DDTHH:MM:SS).
cardLastFourstringThe last four digits of the saved credit card.

chipotle.checkout(orderId, eTag, shapeHeaders, wallet, pickupTime) ⇒ AxiosResponse

Checks out a specified order. Requires shape antibot headers. I don't have access to a shape cookie api so the function is largely undocumented.

Kind: instance method of Chipotle
Returns: AxiosResponse - Returns a response object instead of just the body for debugging purposes.

ParamTypeDescription
orderIdstringThe target order id.
eTagstringThe most recent ETag associated with the order.
shapeHeadersShapeHeadersAn object of shape antibot headers required for order submissions.
walletWalletThe payment method wallet object returned from getWallet.
pickupTimestringThe order pickup time. This should be in the same format returned in getRestaurantPickupTimes (YYYY-MM-DDTHH:MM:SS).

chipotle.login(email, password, maxAttempts)

Logs the browser instance into a Chipotle account.

Kind: instance method of Chipotle

ParamTypeDefaultDescription
emailstringThe account email.
passwordstringThe account password.
maxAttemptsnumber5The max amount of login retry attempts. Default is 5 attempts.

Chipotle.create(email, password, headless, maxAttempts)

Creates a Chipotle object. Also logs into the specified chipotle account with login().

Kind: static method of Chipotle

ParamTypeDefaultDescription
emailstringThe account email.
passwordstringThe account password.
headlessbooleanWhether to start the browser in headless mode or not.
maxAttemptsnumber5The max amount of login retry attempts. default is 5 attempts.
1.0.1

2 years ago

1.0.0

2 years ago