Table of Contents
Order from Amazon Business via your terminal
Saurabh Sharma
CTO @ Rye
Nov 27, 2023
6 min read
Get, set, order
Three API requests - that's all it takes to order from Amazon Business straight from your terminal. In this tutorial, we'll walk you through how to make that happen.
No technical knowledge required! You'll just need a system with Mac or Linux. If you can open the terminal app on your computer, you can run through this tutorial!
Here's a video walkthrough of how it works:
Three API requests - that's all it takes to order from Amazon Business straight from your terminal. In this tutorial, we'll walk you through how to make that happen.
No technical knowledge required! You'll just need a system with Mac or Linux. If you can open the terminal app on your computer, you can run through this tutorial!
Here's a video walkthrough of how it works:
Three API requests - that's all it takes to order from Amazon Business straight from your terminal. In this tutorial, we'll walk you through how to make that happen.
No technical knowledge required! You'll just need a system with Mac or Linux. If you can open the terminal app on your computer, you can run through this tutorial!
Here's a video walkthrough of how it works:
What you’ll need
Sign up on console.rye.com/register
Terminal app, to run the commands
Credit Card, to make the purchase
API Key Headers and Payment Gateway Headers from the Rye API Authentication section on console.rye.com/account
Find something to buy! Specifically, we will need an Amazon Standard Identification Number (ASIN). You can find this on the product page URL on Amazon as shown below:
Step 1: Input all the fields below
We built the marketplace on Medusa JS, an open-source Shopify. It enables composable, headless, and hyper-customizable eCommerce through community architecture. MedusaJS consists of 3 parts: the backend, the admin panel, and the storefront.
We built the marketplace on Medusa JS, an open-source Shopify. It enables composable, headless, and hyper-customizable eCommerce through community architecture. MedusaJS consists of 3 parts: the backend, the admin panel, and the storefront.
We built the marketplace on Medusa JS, an open-source Shopify. It enables composable, headless, and hyper-customizable eCommerce through community architecture. MedusaJS consists of 3 parts: the backend, the admin panel, and the storefront.
1RYE_API_KEY='Basic UllZlWVjYTlhZnU0NjIOYrQwNZgiMWk1Og=='2RYE_SHOPPER_IP='184.13.22.47'3RYE_CARD_TOKENIZATION_SECRET='Basic 5CVTNWcDB2M0dXYWFBaDNxdjJXaDF3dTU0eXE1Y2OOd21xzUU0bBFIeEpGNllUWXE='45CREATE_CART_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://graphql.api.rye.com/v1/query' \6 -H 'Content-Type: application/json' \7 -H "Authorization: <span style="color: #9cdcfe">$RYE_API_KEY"</span> \8 -H "Rye-Shopper-IP: <span style="color: #9cdcfe">$RYE_SHOPPER_IP"</span> \9 -d '{10 "query": "mutation (<span style="color: #9cdcfe">$input:</span> CartCreateInput!) { createCart(input: <span style="color: #9cdcfe">$input)</span> { cart { id } errors { code message } } }",11 "variables": {12 "input": {13 "items": {14 "amazonCartItemsInput": [{15 "quantity": 1,16 "productId": "B004WVZ3"17 }]18 },19 "buyerIdentity": {20 "firstName": "Jane",21 "lastName": "Smith",22 "email": "dev@rye.com",23 "phone": "+15555555555",24 "address1": "123 Main St",25 "address2": "",26 "city": "New York",27 "provinceCode": "NY",28 "countryCode": "US",29 "postalCode": "10001"30 }31 }32 }33 }'34)3536CART_ID=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span> | sed -n 's/.*"id":"\([^"]*\)".*/\1/p')37ERRORS=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span> | sed -n 's/.*"errors":\(\[[^]]*]\).*/\1/p')3839<span style="color: #569cd6">if</span> [ -n "<span style="color: #9cdcfe">$CART_ID"</span> ] && [ "<span style="color: #9cdcfe">$ERRORS"</span> = "[]" ]; <span style="color: #569cd6">then</span>40 <span style="color: #569cd6">echo</span> '✅ Cart successfully created!'41<span style="color: #569cd6">else</span>42 <span style="color: #569cd6">echo</span> '❌ Error: Unable to fetch CART_ID.'43 <span style="color: #569cd6">echo</span> 'Response from server:'44 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span>45<span style="color: #569cd6">fi</span>4647CARD_TOKENIZATION_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://core.spreedly.com/v1/payment_methods.json' \48 -H "Authorization: <span style="color: #9cdcfe">$RYE_CARD_TOKENIZATION_SECRET"</span> \49 -H 'Content-Type: application/json' \50 -d '{51 "payment_method": {52 "credit_card": {53 "first_name": "Jane",54 "last_name": "Smith",55 "number": "4111111111111111",56 "verification_value": "123",57 "month": "01",58 "year": "2029"59 },60 "retained": true61 }62 }'63)6465PAYMENT_METHOD_TOKEN=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CARD_TOKENIZATION_RESPONSE"</span> | sed -n 's/.*"payment_method":{"token":"\([^"]*\)".*/\1/p')6667<span style="color: #569cd6">if</span> [ -n "<span style="color: #9cdcfe">$PAYMENT_METHOD_TOKEN"</span> ]; <span style="color: #569cd6">then</span>68 <span style="color: #569cd6">echo</span> '✅ Card successfully tokenized!'69<span style="color: #569cd6">else</span>70 <span style="color: #569cd6">echo</span> "❌ Error: Unable to fetch PAYMENT_METHOD_TOKEN."71 <span style="color: #569cd6">echo</span> 'Response from server:'72 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$CARD_TOKENIZATION_RESPONSE"</span>73<span style="color: #569cd6">fi</span>7475SUBMIT_CART_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://graphql.api.rye.com/v1/query' \76-H 'Content-Type: application/json' \77-H "Authorization: <span style="color: #9cdcfe">$RYE_API_KEY"</span> \78-H "Rye-Shopper-IP: <span style="color: #9cdcfe">$RYE_SHOPPER_IP"</span> \79-d "<span style="color: #9cdcfe">$(cat</span> <<EOF80{81 "query": "mutation (\<span style="color: #9cdcfe">$input:</span> CartSubmitInput!) { submitCart(input: \<span style="color: #9cdcfe">$input)</span> { cart { id stores { isSubmitted errors { code message } } } errors { code message } } }",82 "variables": {83 "input": {84 "id": "<span style="color: #9cdcfe">$CART_ID",</span>85 "token": "<span style="color: #9cdcfe">$PAYMENT_METHOD_TOKEN"</span>86 }87 }88}89EOF90)")9192IS_SUBMITTED=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span> | sed -n 's/.*"isSubmitted":\([^,]*\).*/\1/p')93ERRORS=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span> | sed -n 's/.*"errors":\(\[[^]]*]\).*/\1/p')9495<span style="color: #569cd6">if</span> [ "<span style="color: #9cdcfe">$IS_SUBMITTED"</span> = "true" ] && [ "<span style="color: #9cdcfe">$ERRORS"</span> = "[]" ]; <span style="color: #569cd6">then</span>96 <span style="color: #569cd6">echo</span> '🎉 Hooray! You ordered an Amazon product from your terminal!'97 <span style="color: #569cd6">echo</span> 'You can view your order on https://console.rye.com/orders'98<span style="color: #569cd6">else</span>99 <span style="color: #569cd6">echo</span> '❌ Error! Unable to submit cart.'100 <span style="color: #569cd6">echo</span> 'Response from server:'101 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span>102<span style="color: #569cd6">fi</span>
1RYE_API_KEY='Basic UllZlWVjYTlhZnU0NjIOYrQwNZgiMWk1Og=='2RYE_SHOPPER_IP='184.13.22.47'3RYE_CARD_TOKENIZATION_SECRET='Basic 5CVTNWcDB2M0dXYWFBaDNxdjJXaDF3dTU0eXE1Y2OOd21xzUU0bBFIeEpGNllUWXE='45CREATE_CART_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://graphql.api.rye.com/v1/query' \6 -H 'Content-Type: application/json' \7 -H "Authorization: <span style="color: #9cdcfe">$RYE_API_KEY"</span> \8 -H "Rye-Shopper-IP: <span style="color: #9cdcfe">$RYE_SHOPPER_IP"</span> \9 -d '{10 "query": "mutation (<span style="color: #9cdcfe">$input:</span> CartCreateInput!) { createCart(input: <span style="color: #9cdcfe">$input)</span> { cart { id } errors { code message } } }",11 "variables": {12 "input": {13 "items": {14 "amazonCartItemsInput": [{15 "quantity": 1,16 "productId": "B004WVZ3"17 }]18 },19 "buyerIdentity": {20 "firstName": "Jane",21 "lastName": "Smith",22 "email": "dev@rye.com",23 "phone": "+15555555555",24 "address1": "123 Main St",25 "address2": "",26 "city": "New York",27 "provinceCode": "NY",28 "countryCode": "US",29 "postalCode": "10001"30 }31 }32 }33 }'34)3536CART_ID=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span> | sed -n 's/.*"id":"\([^"]*\)".*/\1/p')37ERRORS=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span> | sed -n 's/.*"errors":\(\[[^]]*]\).*/\1/p')3839<span style="color: #569cd6">if</span> [ -n "<span style="color: #9cdcfe">$CART_ID"</span> ] && [ "<span style="color: #9cdcfe">$ERRORS"</span> = "[]" ]; <span style="color: #569cd6">then</span>40 <span style="color: #569cd6">echo</span> '✅ Cart successfully created!'41<span style="color: #569cd6">else</span>42 <span style="color: #569cd6">echo</span> '❌ Error: Unable to fetch CART_ID.'43 <span style="color: #569cd6">echo</span> 'Response from server:'44 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span>45<span style="color: #569cd6">fi</span>4647CARD_TOKENIZATION_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://core.spreedly.com/v1/payment_methods.json' \48 -H "Authorization: <span style="color: #9cdcfe">$RYE_CARD_TOKENIZATION_SECRET"</span> \49 -H 'Content-Type: application/json' \50 -d '{51 "payment_method": {52 "credit_card": {53 "first_name": "Jane",54 "last_name": "Smith",55 "number": "4111111111111111",56 "verification_value": "123",57 "month": "01",58 "year": "2029"59 },60 "retained": true61 }62 }'63)6465PAYMENT_METHOD_TOKEN=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CARD_TOKENIZATION_RESPONSE"</span> | sed -n 's/.*"payment_method":{"token":"\([^"]*\)".*/\1/p')6667<span style="color: #569cd6">if</span> [ -n "<span style="color: #9cdcfe">$PAYMENT_METHOD_TOKEN"</span> ]; <span style="color: #569cd6">then</span>68 <span style="color: #569cd6">echo</span> '✅ Card successfully tokenized!'69<span style="color: #569cd6">else</span>70 <span style="color: #569cd6">echo</span> "❌ Error: Unable to fetch PAYMENT_METHOD_TOKEN."71 <span style="color: #569cd6">echo</span> 'Response from server:'72 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$CARD_TOKENIZATION_RESPONSE"</span>73<span style="color: #569cd6">fi</span>7475SUBMIT_CART_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://graphql.api.rye.com/v1/query' \76-H 'Content-Type: application/json' \77-H "Authorization: <span style="color: #9cdcfe">$RYE_API_KEY"</span> \78-H "Rye-Shopper-IP: <span style="color: #9cdcfe">$RYE_SHOPPER_IP"</span> \79-d "<span style="color: #9cdcfe">$(cat</span> <<EOF80{81 "query": "mutation (\<span style="color: #9cdcfe">$input:</span> CartSubmitInput!) { submitCart(input: \<span style="color: #9cdcfe">$input)</span> { cart { id stores { isSubmitted errors { code message } } } errors { code message } } }",82 "variables": {83 "input": {84 "id": "<span style="color: #9cdcfe">$CART_ID",</span>85 "token": "<span style="color: #9cdcfe">$PAYMENT_METHOD_TOKEN"</span>86 }87 }88}89EOF90)")9192IS_SUBMITTED=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span> | sed -n 's/.*"isSubmitted":\([^,]*\).*/\1/p')93ERRORS=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span> | sed -n 's/.*"errors":\(\[[^]]*]\).*/\1/p')9495<span style="color: #569cd6">if</span> [ "<span style="color: #9cdcfe">$IS_SUBMITTED"</span> = "true" ] && [ "<span style="color: #9cdcfe">$ERRORS"</span> = "[]" ]; <span style="color: #569cd6">then</span>96 <span style="color: #569cd6">echo</span> '🎉 Hooray! You ordered an Amazon product from your terminal!'97 <span style="color: #569cd6">echo</span> 'You can view your order on https://console.rye.com/orders'98<span style="color: #569cd6">else</span>99 <span style="color: #569cd6">echo</span> '❌ Error! Unable to submit cart.'100 <span style="color: #569cd6">echo</span> 'Response from server:'101 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span>102<span style="color: #569cd6">fi</span>
1RYE_API_KEY='Basic UllZlWVjYTlhZnU0NjIOYrQwNZgiMWk1Og=='2RYE_SHOPPER_IP='184.13.22.47'3RYE_CARD_TOKENIZATION_SECRET='Basic 5CVTNWcDB2M0dXYWFBaDNxdjJXaDF3dTU0eXE1Y2OOd21xzUU0bBFIeEpGNllUWXE='45CREATE_CART_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://graphql.api.rye.com/v1/query' \6 -H 'Content-Type: application/json' \7 -H "Authorization: <span style="color: #9cdcfe">$RYE_API_KEY"</span> \8 -H "Rye-Shopper-IP: <span style="color: #9cdcfe">$RYE_SHOPPER_IP"</span> \9 -d '{10 "query": "mutation (<span style="color: #9cdcfe">$input:</span> CartCreateInput!) { createCart(input: <span style="color: #9cdcfe">$input)</span> { cart { id } errors { code message } } }",11 "variables": {12 "input": {13 "items": {14 "amazonCartItemsInput": [{15 "quantity": 1,16 "productId": "B004WVZ3"17 }]18 },19 "buyerIdentity": {20 "firstName": "Jane",21 "lastName": "Smith",22 "email": "dev@rye.com",23 "phone": "+15555555555",24 "address1": "123 Main St",25 "address2": "",26 "city": "New York",27 "provinceCode": "NY",28 "countryCode": "US",29 "postalCode": "10001"30 }31 }32 }33 }'34)3536CART_ID=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span> | sed -n 's/.*"id":"\([^"]*\)".*/\1/p')37ERRORS=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span> | sed -n 's/.*"errors":\(\[[^]]*]\).*/\1/p')3839<span style="color: #569cd6">if</span> [ -n "<span style="color: #9cdcfe">$CART_ID"</span> ] && [ "<span style="color: #9cdcfe">$ERRORS"</span> = "[]" ]; <span style="color: #569cd6">then</span>40 <span style="color: #569cd6">echo</span> '✅ Cart successfully created!'41<span style="color: #569cd6">else</span>42 <span style="color: #569cd6">echo</span> '❌ Error: Unable to fetch CART_ID.'43 <span style="color: #569cd6">echo</span> 'Response from server:'44 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$CREATE_CART_RESPONSE"</span>45<span style="color: #569cd6">fi</span>4647CARD_TOKENIZATION_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://core.spreedly.com/v1/payment_methods.json' \48 -H "Authorization: <span style="color: #9cdcfe">$RYE_CARD_TOKENIZATION_SECRET"</span> \49 -H 'Content-Type: application/json' \50 -d '{51 "payment_method": {52 "credit_card": {53 "first_name": "Jane",54 "last_name": "Smith",55 "number": "4111111111111111",56 "verification_value": "123",57 "month": "01",58 "year": "2029"59 },60 "retained": true61 }62 }'63)6465PAYMENT_METHOD_TOKEN=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$CARD_TOKENIZATION_RESPONSE"</span> | sed -n 's/.*"payment_method":{"token":"\([^"]*\)".*/\1/p')6667<span style="color: #569cd6">if</span> [ -n "<span style="color: #9cdcfe">$PAYMENT_METHOD_TOKEN"</span> ]; <span style="color: #569cd6">then</span>68 <span style="color: #569cd6">echo</span> '✅ Card successfully tokenized!'69<span style="color: #569cd6">else</span>70 <span style="color: #569cd6">echo</span> "❌ Error: Unable to fetch PAYMENT_METHOD_TOKEN."71 <span style="color: #569cd6">echo</span> 'Response from server:'72 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$CARD_TOKENIZATION_RESPONSE"</span>73<span style="color: #569cd6">fi</span>7475SUBMIT_CART_RESPONSE=<span style="color: #9cdcfe">$(curl</span> -s 'https://graphql.api.rye.com/v1/query' \76-H 'Content-Type: application/json' \77-H "Authorization: <span style="color: #9cdcfe">$RYE_API_KEY"</span> \78-H "Rye-Shopper-IP: <span style="color: #9cdcfe">$RYE_SHOPPER_IP"</span> \79-d "<span style="color: #9cdcfe">$(cat</span> <<EOF80{81 "query": "mutation (\<span style="color: #9cdcfe">$input:</span> CartSubmitInput!) { submitCart(input: \<span style="color: #9cdcfe">$input)</span> { cart { id stores { isSubmitted errors { code message } } } errors { code message } } }",82 "variables": {83 "input": {84 "id": "<span style="color: #9cdcfe">$CART_ID",</span>85 "token": "<span style="color: #9cdcfe">$PAYMENT_METHOD_TOKEN"</span>86 }87 }88}89EOF90)")9192IS_SUBMITTED=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span> | sed -n 's/.*"isSubmitted":\([^,]*\).*/\1/p')93ERRORS=<span style="color: #9cdcfe">$(<span style="color: #569cd6">echo</span></span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span> | sed -n 's/.*"errors":\(\[[^]]*]\).*/\1/p')9495<span style="color: #569cd6">if</span> [ "<span style="color: #9cdcfe">$IS_SUBMITTED"</span> = "true" ] && [ "<span style="color: #9cdcfe">$ERRORS"</span> = "[]" ]; <span style="color: #569cd6">then</span>96 <span style="color: #569cd6">echo</span> '🎉 Hooray! You ordered an Amazon product from your terminal!'97 <span style="color: #569cd6">echo</span> 'You can view your order on https://console.rye.com/orders'98<span style="color: #569cd6">else</span>99 <span style="color: #569cd6">echo</span> '❌ Error! Unable to submit cart.'100 <span style="color: #569cd6">echo</span> 'Response from server:'101 <span style="color: #569cd6">echo</span> "<span style="color: #9cdcfe">$SUBMIT_CART_RESPONSE"</span>102<span style="color: #569cd6">fi</span>
Step 2: Run the commands in terminal
We built the marketplace on Medusa JS, an open-source Shopify. It enables composable, headless, and hyper-customizable eCommerce through community architecture. MedusaJS consists of 3 parts: the backend, the admin panel, and the storefront.
✅ Cart successfully created!
✅ Card successfully tokenized!
🎉 Hooray! You ordered an Amazon Business product from your terminal!
You can view your order on https://console.rye.com/orders
We built the marketplace on Medusa JS, an open-source Shopify. It enables composable, headless, and hyper-customizable eCommerce through community architecture. MedusaJS consists of 3 parts: the backend, the admin panel, and the storefront.
✅ Cart successfully created!
✅ Card successfully tokenized!
🎉 Hooray! You ordered an Amazon Business product from your terminal!
You can view your order on https://console.rye.com/orders
We built the marketplace on Medusa JS, an open-source Shopify. It enables composable, headless, and hyper-customizable eCommerce through community architecture. MedusaJS consists of 3 parts: the backend, the admin panel, and the storefront.
✅ Cart successfully created!
✅ Card successfully tokenized!
🎉 Hooray! You ordered an Amazon Business product from your terminal!
You can view your order on https://console.rye.com/orders
Related articles
Related articles
Accelerate your commerce operations
Accelerate your commerce operations
Accelerate your commerce operations
Product
Resources
Solutions