Sell Anything API
In this tutorial, you’ll understand how to use Rye’s Sell Anything API to create a cart, add products to it, and submit it for checkout.
Requirements
- You have created a Rye Developer Account.
- You have access to your API key (Follow these steps if not).
Let’s begin!
Initialize GQL client with your API key
Use your API Key to initialize authorization headers for your GQL client.
Add external product to Rye inventory
Adding product data to inventory may take a few seconds, but the product ID will be returned immediately. You can then use this product ID to fetch product data in the next step. You can also do this via the Rye Console, under the “Requests” tab.
Fetch product data from Rye inventory
The product ID can be found in the response to the requestAmazonProductByURL
mutation’s response.
Create a cart
We can create a cart containing the Amazon product we just requested.
Use a fragment
In the previous step our GraphQL document was extremely long. We can cut down on duplication by extracting our selected fields out as a reusable fragment, like so:
Add more products to your cart
Add more products to your cart with the product IDs and the cart ID of the desired cart, using the addCartItems
mutation.
Fetch cart shipping methods and cost
Check if your cart looks good, and fetch the estimated checkout cost and available shipping methods for the cart.
Update buyer identity
Update buyer identity information if it was not provided during cart creation as it is required to be able to submit the cart.
Submit your cart
Submit your cart via Rye Pay. For information on setting up a generateJWT
method, see our tutorial.
Display the results of the transaction
After ryePay.submit
submits your cart, it will call your onCartSubmitted
callback with a snapshot of the cart post-checkout. In some cases there may have been some errors during the submission of the cart, and these can be inspected on the result
object.
Errors can occur on the Cart level and the Store level:
- For the cart level:
result.errors
will provide an array of errors related to submitting the cart with appropriate error messages and codes - For the store level:
result.cart.stores[idx].errors
will provide an array of errors related to submitting the order to the store with appropriate error messages and codes
It is important to remember that submitting a cart is an async operation. It is possible for errors to occur after you have submitted the cart. Read more about checkout lifecycle here.
Cart management
- To update the number of existing products in the cart, use the
updateCartItems
mutation. - To remove existing products from the cart, use the
deleteCartItems
mutation. - To remove the entire cart, use the
removeCart
mutation.
Next steps
- We looked at
requestAmazonProductByURL
in this guide, butrequestShopifyProductByURL
andrequestStoreByURL
can also be used to add products to our product data catalog. - Check out our “starting an integration” guide to get started with building out your real API integration.
- Experiment with our API using one of the following playgrounds:
Before you can make GraphQL requests, you will need to set the correct HTTP headers. Check out our Authorization guide for details.
Was this page helpful?