Skip to content

Instantly share code, notes, and snippets.

@jcowhigjr
Created November 5, 2012 23:58
Show Gist options
  • Save jcowhigjr/4021246 to your computer and use it in GitHub Desktop.
Save jcowhigjr/4021246 to your computer and use it in GitHub Desktop.
Spree API REST Examples

Products

index of products 25 first

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products.json

Show a product

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products/706676762.json

Modify a product

curl -i -X PUT -H "X-Spree-Token: YOUR_TOKEN_ID" -d "product[name]=Headphones" http://0.0.0.0:3000/api/products/706676762.json

Delete a product

curl -i -X DELETE -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products/706676762.json

New product

curl -i -X GET -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products/new.json

Create a product

curl -i -X POST -H "X-Spree-Token: YOUR_TOKEN_ID" -d "product[name]=Headphefsefones&product[price]=100" http://0.0.0.0:3000/api/products

Search products

curl -i -X GET -H "X-Spree-Token: YOUR_TOKEN_ID" -d "q[name_cont]=Rails" http://0.0.0.0:3000/api/products/search.json

Variants

Index of variants

curl -i -X GET -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/variants.json

New variant

curl -i -X GET -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products/596960057/variants/new.json

DOES NOT WORK : create a variant

curl -i -X POST -H "X-Spree-Token: YOUR_TOKEN_ID" -d "variant[price]=100&product=596960057" http://0.0.0.0:3000/api/variants

curl -i -X POST -H "X-Spree-Token: YOUR_TOKEN_ID" -d "variant[price]=100" http://0.0.0.0:3000/api/products/596960057/variants

curl -i -X POST -H "X-Spree-Token: YOUR_TOKEN_ID" -d "variant[name]=100" http://0.0.0.0:3000/api/products/596960057/variants

Modify a variant###

curl -i -X PUT -H "X-Spree-Token: YOUR_TOKEN_ID" -d "variant[price]=100" http://0.0.0.0:3000/api/products/596960057/variants/748173072

Delete a variant###

curl -i -X DELETE -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products/596960057/variants/748173072

Orders

Index of orders###

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/orders

Show an order

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/orders/R764617307

Create an order

curl -i -X POST -H "X-Spree-Token: YOUR_TOKEN_ID" -d "order[line_items][][variant_id]=748173072&order[line_items[][quantity]=5" http://0.0.0.0:3000/api/orders

Capture payment

curl -i -X PUT -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/orders/R570383062/payments/28/purchase -d ""

Update order status

curl -i -X PUT -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/orders/R243081821/shipments/H48741317988/ship -d ""

Search an order

curl -i -X GET -H "X-Spree-Token: YOUR_TOKEN_ID" -d "q[number_cont]=R243081821" http://0.0.0.0:3000/api/orders/search.json

Taxonomies

Index of taxonomies

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/taxonomies.json

Show a taxonomy

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/taxonomies/475199832.json

Modify a taxonomy

curl -i -X PUT -H "X-Spree-Token: YOUR_TOKEN_ID" -d "taxonomy[name]=Headphones" http://0.0.0.0:3000/api/taxonomies/854451430.json

Delete a taxonomy

curl -i -X DELETE -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/taxonomies/475199832.json

New taxonomy

curl -i -X GET -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/taxonomies/new.json

Create a taxonomy

curl -i -X POST -H "X-Spree-Token: YOUR_TOKEN_ID" -d "taxonomy[name]=Headphefsefones" http://0.0.0.0:3000/api/taxonomies

@radar
Copy link

radar commented Sep 10, 2013

The route for /api/orders/search.json is now /api/orders.json.

@willgm
Copy link

willgm commented Apr 1, 2015

How do I search products with more than one key word? I have tryed without success:

curl -i -X GET -H "X-Spree-Token: YOUR_TOKEN_ID" -d "q[name_cont]=Ruby+Rails" http://0.0.0.0:3000/api/products/search.json

curl -i -X GET -H "X-Spree-Token: YOUR_TOKEN_ID" -d "q[name_cont]=Ruby%20Rails" http://0.0.0.0:3000/api/products/search.json

@Qwertie-
Copy link

Should be updated to include the api version. /api/products.json is now /api/v1/products.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment