Skip to content

Instantly share code, notes, and snippets.

@tshabatyn
Last active July 2, 2020 07:32
Show Gist options
  • Select an option

  • Save tshabatyn/057b11f2da2debc75985413739c34884 to your computer and use it in GitHub Desktop.

Select an option

Save tshabatyn/057b11f2da2debc75985413739c34884 to your computer and use it in GitHub Desktop.
BASE_URL='http://php70.magento2.local/ee214'
TOKEN=$(curl -sS -g -X POST "$BASE_URL/index.php/rest/V1/integration/customer/token" \
-H "Content-Type:application/json" \
-d '{"username":"[email protected]", "password":"[email protected]"}' | sed 's#"##g')
echo ${TOKEN}
# Get product info
curl -sS -g -X GET "$BASE_URL/index.php/rest/V1/products/MH01/" \
-H "Authorization: Bearer $TOKEN" \
| json_pp
# Get new shopping cart
curl -sS -g -X POST "$BASE_URL/index.php/rest/V1/guest-carts/" \
-H "Authorization: Bearer ${TOKEN}"
SHOPPING_CART="c7e054951654eeed1fd26d7d8c24cb00" && echo $SHOPPING_CART
# Get shopping cart info
curl -sS -g -X GET "$BASE_URL/index.php/rest/V1/guest-carts/${SHOPPING_CART}" \
-H "Authorization: Bearer ${TOKEN}" \
| json_pp
# Add configurable product to the cart
curl -sS -g -X POST "$BASE_URL/index.php/rest/V1/guest-carts/$SHOPPING_CART/items" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type:application/json" \
-d "{
\"cartItem\": {
\"quote_id\": \"$SHOPPING_CART\",
\"sku\": \"MH01\",
\"qty\": 1,
\"product_type\": \"configurable\",
\"product_option\": {
\"extension_attributes\": {
\"configurable_item_options\": [
{
\"option_id\": 93,
\"option_value\": 65
},
{
\"option_id\": 184,
\"option_value\": 181
}
]
}
}
}
}" \
| json_pp
ITEM_ID=26
# Change qty of the product in the cart
curl -sS -g -X PUT "$BASE_URL/index.php/rest/V1/guest-carts/$SHOPPING_CART/items/$ITEM_ID" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type:application/json" \
-d "{
\"cartItem\": {
\"quote_id\": \"$SHOPPING_CART\",
\"sku\": \"MH01\",
\"qty\": 20,
\"product_type\": \"configurable\",
\"product_option\": {
\"extension_attributes\": {
\"configurable_item_options\": [
{
\"option_id\": 93,
\"option_value\": 65
},
{
\"option_id\": 184,
\"option_value\": 181
}
]
}
}
}
}" \
| json_pp
### Add simple product to the cart
# Get product info
curl -sS -g -X GET "$BASE_URL/index.php/rest/V1/products/24-MB04/" \
-H "Authorization: Bearer $TOKEN" \
| json_pp
curl -sS -g -X POST "$BASE_URL/index.php/rest/V1/guest-carts/$SHOPPING_CART/items" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type:application/json" \
-d "{ \"cartItem\": { \"quote_id\": \"$SHOPPING_CART\", \"sku\": \"24-MB06\", \"qty\": 300 } }" \
| json_pp
ITEM_ID="19"
curl -sS -g -X PUT "$BASE_URL/index.php/rest/V1/guest-carts/$SHOPPING_CART/items/$ITEM_ID" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type:application/json" \
-d "{ \"cartItem\": { \"quote_id\": \"$SHOPPING_CART\", \"sku\": \"24-MB05\", \"qty\": 1000 } }" \
| json_pp
curl -sS -g -X POST "$BASE_URL/index.php/rest/V1/guest-carts/$SHOPPING_CART/shipping-information" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type:application/json" \
-d '{
"addressInformation": {
"shippingAddress": {
"region": "CA",
"region_id": 12,
"country_id": "US",
"street": [
"Test"
],
"company": "Test",
"telephone": "555 055 55 55",
"postcode": "94608",
"city": "Test",
"firstname": "Test",
"lastname": "Test",
"email": "[email protected]",
"prefix": "address_",
"region_code": "CA",
"sameAsBilling": 1
},
"billingAddress": {
"region": "CA",
"region_id": 12,
"country_id": "US",
"street": [
"Test"
],
"company": "Test",
"telephone": "555 055 55 55",
"postcode": "94608",
"city": "Test",
"firstname": "Test",
"lastname": "Test",
"email": "[email protected]",
"prefix": "address_",
"region_code": "CA"
},
"shipping_method_code": "flatrate",
"shipping_carrier_code": "flatrate"
}
}' \
| json_pp
curl -sS -g -X GET "$BASE_URL/index.php/rest/V1/guest-carts/$SHOPPING_CART/payment-information" \
-H "Authorization: Bearer $TOKEN" \
| json_pp
curl -sS -g -X GET "$BASE_URL/index.php/rest/V1/guest-carts/$SHOPPING_CART/shipping-information" \
-H "Authorization: Bearer $TOKEN" \
| json_pp
curl -sS -g -X PUT "$BASE_URL/index.php/rest/V1/guest-carts/$SHOPPING_CART/order" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type:application/json" \
-d '
{
"method": {
"method": "cashondelivery"
}
}
' \
| json_pp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment