Ad

Why Am I Forbidden From Creating A Checkout Using The Shopify API Ruby Gem

- 1 answer

Is any using the Shopify API rub gem? I'm building a headless storefront where few things not working. I can fetch Products but cannot create a checkout so I can add items to cart.

Ruby: 2.7.0 Rails: 6.0.2.1

The setup:

config/initializers/shopify.rb:

shop_url = "https://#{ENV['SHOPIFY_API_KEY']}:#{ENV['SHOPIFY_PASSWORD']}@#{ENV['SHOP_NAME']}.myshopify.com"
ShopifyAPI::Base.site = shop_url
ShopifyAPI::Base.api_version = ENV['STORE_API_VERSION'] # find the latest stable api_version [here](https://help.shopify.com/api/versioning)

The above is per docs as Im using a private app.

In a controller:

product = ShopifyAPI::Product.find('12345678')
# This works fine. Now:

checkout = ShopifyAPI::Checkout.create
# <ActiveResource::ForbiddenAccess: Failed.  Response code = 403.  Response message = Forbidden.>

The create I got from their tests but it's "blowing up".

I tried to understand how to add items to cart and their JS example shows that on page load, they create a checkout then use its id when adding items to cart.

Though my frontend is JS, everything runs through Rails.

Thanks.

Ad

Answer

The Checkout API requires your APP to be public.

In addition your app must be set as a Sales Channel ( which privates APP's can't do, that's why you need a public one ) and your products must be available to that sales channel in order to add them to the checkout.

As an alternative you can use the Storefront API https://help.shopify.com/en/api/storefront-api/reference/mutation/checkoutcreate

Ad
source: stackoverflow.com
Ad