Overview

Rye’s API allows you to place Amazon orders entirely through backend TypeScript code. By offloading order processing to Rye, you can easily submit Amazon purchases for fulfillment via API calls. This guide covers the key steps in the process. For a complete TypeScript code example, check out our demo. Python documentation coming soon.

Key Steps

  1. Create a Rye cart with the Amazon items (createCart mutation)
  2. Collect payment from the customer based on the cart’s cost field
  3. Submit the Amazon order with the submitCart mutation

Pre-reqs:

  1. Make sure to replace <Authorization>, <Shopper-IP> and PRODUCTION_PAYMENT_GATEWAY_HEADERS with your actual values from the Rye Console.
  2. Modify the product details, buyer identity, and credit card information as needed to suit your specific use case.
If everything is set up correctly, you should see the order submission status and response logged in the console.

How to run:

To run this example, you’ll need to install the necessary dependencies using Yarn:
yarn add @rye-api/rye-sdk axios ts-node typescript
To run the example, use the following command:
yarn run ts-node index.ts
import { RyeClient, CartItemsInput, Country } from '@rye-api/rye-sdk';

// You can find these in the Rye Console at console.rye.com/account
const API_HEADERS = {"Authorization": "Basic <Authorization>", "Rye-Shopper-IP": "<Shopper-IP>"};
const ryeClient = new RyeClient({authHeader: API_HEADERS.Authorization, shopperIp: API_HEADERS["Rye-Shopper-IP"]});

async function main() {
  // Create a new cart with an Amazon product
  const createCartResponse = await ryeClient.createCart({
    input: {
      items: { amazonCartItemsInput: [{ productId: 'B01I2Y4GVY', quantity: 1 }] },
      buyerIdentity: {
        firstName: 'Jane', lastName: 'Smith', phone: '+14152940424',
        email: 'jane@example.com', address1: '123 Main St', city: 'San Francisco',
        countryCode: Country.Us, provinceCode: 'CA', postalCode: '94111',
      },
    },
  });

  // Submit the cart to create an order
  const submitCartResponse = await ryeClient.submitCart({
    input: { id: createCartResponse!.cart.id! },
  });

  // Log the order submission status and response
  console.log(`Order submitted! Status: ${submitCartResponse!.cart.stores[0]!.status!},\n${JSON.stringify(submitCartResponse)}`);
}

main().catch(console.error);
The index.ts file contains the main logic for creating an order. It creates a new cart with an Amazon product, and submits the cart to create an order. The order submission status and response are logged to the console.