Skip to content

Instantly share code, notes, and snippets.

@heridev
Last active February 3, 2023 14:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save heridev/9256948 to your computer and use it in GitHub Desktop.
Save heridev/9256948 to your computer and use it in GitHub Desktop.
Spree, spree api, spree routes, Spree Routes, routes spree, endpoints spree, spree endpoints, api spree, spree api, api queries

More examples using spree demo on heroku

curl -d 'spree_user[email]=spree@example.com&spree_user[password]=spree123' http://spree-demo-store.herokuapp.com/api/v1/authorizations

curl -i -H "X-Spree-Token: 5e06dc07fda2b1e4b6ba792ba18e5d964d567cf33a575f55" http://spree-demo-store.herokuapp.com/api/products.json

curl -i -H "X-Spree-Token: 5e06dc07fda2b1e4b6ba792ba18e5d964d567cf33a575f55" http://spree-demo-store.herokuapp.com/api/products/706676762.json

// Requests for users type customer that have been used the public registration to the store

//After to create a user(customer) with a valid token 
curl -i -H "X-Spree-Token: 0aed41983438073fea3e1472e94c87c1ca21bb4f517b828a" http://spree-demo-store.herokuapp.com/api/orders/mine.json

// Get public products you need a valid user token
curl -i -H "X-Spree-Token: 0aed41983438073fea3e1472e94c87c1ca21bb4f517b828a" http://spree-demo-store.herokuapp.com/api/products.json


curl -d 'spree_user[email]=admin@crowdint.com&spree_user[password]=Crowdint$' http://spree-demo-store.herokuapp.com/api/users


curl -H "X-Spree-Token: 0aed41983438073fea3e1472e94c87c1ca21bb4f517b828a" -d 'spree_user[email]=jorge@example.com&spree_user[password]=spree123' http://spree-demo-store.herokuapp.com/api/users

curl -d 'user[email]=admin@crowdint.com&user[password]=cr0wd1nt&user[password_confirmation]=cr0wd1nt' http://localhost:3000/api/users

curl -d 'spree_user[email]=spree@example.com&spree_user[password]=spree123' http://localhost:3000/api/v1/authorizations

curl -i -H "X-Spree-Token: 5e8781aa6203b16956b67608e1122d5700589e9ac69a6b32" http://localhost:3000/api/products.json

curl -i -H "X-Spree-Token: 5e06dc07fda2b1e4b6ba792ba18e5d964d567cf33a575f55" http://localhost:3000/api/products/706676762.json

curl -i http://spree-demo-store.herokuapp.com/api/products.json

esto = {"email"=>"jorge@example.com", "password"=>"spree123", "password_confirmation"=>"spree123"}

 @user = Spree.user_class.new({'email' => 'algo@examlpe.com', 'password'=> 'spree123', 'password_confirmation' => 'spree123'})

 @user = Spree.user_class.new(esto)

user = Spree::User.find_by(email: 'admin@crowdint.com')
user.spree_roles << Spree::Role.find_or_create_by(name: "admin")

curl -d 'user[email]=admin@crowdint.com&user[password]=cr0wd1nt&user[password_confirmation]=cr0wd1nt' http://spree-demo-store.herokuapp.com/api/users

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 using the user admin token###

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

Show an order using the order token

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

$.ajax({
    url: Spree.routes.root + '/api/orders/R233541761?order_token=776b983f944b052a',
    async: false,
    success: function(data) {
      console.log(data);
  }
});

OR

$.ajax({
    url: Spree.routes.root + '/api/orders/'+RevoEyewear.OrderNumber,
    headers: { 'X-Spree-Token': '4e512ffe96f43bb33b0ffac753ac02bf11a679cc6b66736d' },
    success: function(data) {
      console.log(data);
  }
});

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

data

sensitive data

@Akshaysimha
Copy link

curl -d 'user[email]=admin@crowdint.com&user[password]=cr0wd1nt&user[password_confirmation]=cr0wd1nt' http://localhost:3000/api/users

I'm using about api to create user but i'm getting {"error":"You must specify an API key."}

cant I create a user without providing API key?

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