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);