Skip to content

Instantly share code, notes, and snippets.

@spenthil
Created July 2, 2013 19:37
Show Gist options
  • Save spenthil/5912415 to your computer and use it in GitHub Desktop.
Save spenthil/5912415 to your computer and use it in GitHub Desktop.
shirts.io GET /quote/ endpoint
import requests
api_key = "PRAGMATISMPLZ"
shirtsio_url = "https://www.shirts.io/api/v1"
def shirtsio_get(endpoint, params=None):
params = params or dict()
params["api_key"] = api_key
response = requests.get(shirtsio_url + endpoint, params=params)
if response.status_code != 200:
try:
explanation = response.json()
except ValueError:
explanation = response.text
raise Exception("{}: {}".format(explanation, response.url))
return response.json()["result"]
def shirtsio_quote(product_id, color, sizes):
assert set(sizes.keys()).issubset({"xxsml", "xsml", "sml", "med", "lrg", "xlg", "xxl", "xxxl", "xxxxl", "xxxxxl", "xxxxxxl"})
params = {
"api_key": api_key,
"garment": [
{
"color": color,
"sizes": sizes,
},
],
"print": {
"front": {
"color_count": 11, # color_count 11 for full color
},
},
"print_type": "Digital Print",
}
return shirtsio_get("/quote/", params)
shirtsio_quote(31, "Baby Blue", {"med": 1})
# Exception: APPLICATION ERROR: 'list' object has no attribute 'iteritems': https://www.shirts.io/api/v1/quote/?print=front&garment=color&garment=sizes&print_type=Digital+Print&api_key=PRAGMATISMPLZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment