createCart mutation)submitCart mutation<Authorization>, <Shopper-IP> and PRODUCTION_PAYMENT_GATEWAY_HEADERS with your actual values from the Rye Console.1yarn add @rye-api/rye-sdk axios ts-node typescript
1yarn run ts-node index.ts
1234567891011121314151617181920212223242526272829import { 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);
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.