|
Api
API for the Online Co-op Software
Featured IntroductionThe software provides a number of Javascript/JSON-based hooks into the system to retrieve data. This page outlines those functions. URIs in this DocumentThese URI's are based on the root of where the software is hosted from. In the case of the West Michigan Co-op, that's the root, so if the URI was /exampleURI, the full URL would be http://www.westmichigancoop.com/exampleURI. You would replace that domain name with your domain name, and if you host this software from a sub-directory, you would add that sub-directory as well. URI's end in '.json', even when specifying a callback, when the desired result is either a JSON object, or a JSON object wrapped in a callback function. URI's end in '.rss' when the desired result is an RSS (version 2) feed. As yet, there are no documented API functions that add or modify data on the Co-op. We currently only support reads - getting producer information, product information, and delivery cycle information. Anything you can read on the site, but would need to screen-scrape, we are trying to provide in a programmer-friendly format. Specifying ParametersParameters are specified with the format parameter-name:parameter-value. Both the names and values should be URL Encoded, so that a ':' in a name or value isn't confused by the server for the ':' delimiter between the name and value. Multiple parameters are separated by '/'. Two examples:
This calls the function '/deliveries/current' with a parameter 'callback' equal to 'callbackFunction'. That will yeild the JSON object wrapped in 'callbackFunction();' This calls the function'/products/search' with parameters 'name' equal to 'Bacon' and 'from' equal to Creswick. It will return only the JSON object; no callback function. Note that the callback parameter can be specified for any JSON request. That way, you can create a <script> tag to pull data across domains. Supported FunctionsProduct Search
Acquire an array of JSON objects that are data for products currently listed on the site. Multiple query parameters result in an AND - we currently do not have OR based queries. Example: http://www.westmichigancoop.com/products/search/name:Bacon/from:Creswick.json Returns: an array of Product objects (outlined below) that have 'Bacon' in the name AND 'Creswick' in the business name. Note that for historical (read: old database) reasons, the 'description' of an item is stored in a field called 'detailed_notes'. There are other parameters that you can use for exact matches: any database field that is returned in the query can be used to match or order results. Note that as a shortcut, exact matches for product_name and unit_price do not include 'Product.' in front - but they can, and it's perfectly valid. Each product object essentially looks like the following: {
Product: {
product_id: 1234,
product_name: 'Bacon',
unit_price: '9',
pricing_unit: 'pound',
ordering_unit: 'package',
random_weight: '1',
maximum_weight: '2',
minimum_weight: '.5',
created: 'DATETIME',
modified: 'DATETIME',
detailed_notes: "Bacon is delicious."
},
Orderable: {
id: 4563,
inventory_left: 23
},
Member: {
business_name: 'Creswick Farms'
}
}There will be other fields, but this covers the basics of what you'd need. You can always use a JSON inspector to look at some more of the fields you'll get - in general you get quite a lot! You can also use this URL on the main site - if you drop the .json, you will get a search page in your browser that shows you what a shopper would see searching with those parameters. Try the example url, minus the JSON: http://www.westmichigancoop.com/products/search/name:Bacon/from:Creswick Delivery Cycle Information
Get a JSON object containing data about the current delivery cycle dates and times. None, save the callback parameter available for every JSON function. Example: http://www.westmichigancoop.com/deliveries/current/callback:my_function.json Returns: (a direct copy of the current cycle info as of 3/20/2009) my_function({
"Delivery": {
"delivery_id":"67",
"open":"1",
"edit_open":"2009-03-01 00:00:00",
"order_open":"2009-03-07 00:00:00",
"delivery_open":"2009-03-25 17:15:00",
"order_closed":"2009-03-14 00:00:00",
"msg_all":"",
"msg_bottom":"",
"special_order":"0",
"delivery_closed":"2009-03-25 20:00:00",
"pickup_open":"2009-03-25 17:45:00",
"pickup_closed":"2009-03-25 20:00:00"
}
});
|