π§ββοΈInstalling Smartrr on a headless store
Implementing Smartrr on headless storefronts using the Shopify Plus API
Last updated
Implementing Smartrr on headless storefronts using the Shopify Plus API
Last updated
Last updated: April 3, 2024
Note: before implementing Smartrr, it's important to review Shopify's subscription requirements to determine your eligibility for offering subscriptions on your storefront. You must also have inventory tracking enabled for a product to be subscription-eligible.
As of 2023, Shopify has begun offering New customer accounts as a setting option. New customer accounts are not compatible with apps; please ensure you are using Classic customer accounts with Smartrr in order to display our Modern Account Portal where your customers will be able to access and manage their subscriptions.
From the Shopify app store, install the Smartrr app.
In your Shopify admin ([your-store-name].myshopify.com), navigate to 'Apps'. The Smartrr app should now show on your app list.
Click on the Smartrr app to open. Navigate to the Integrations tab in the left-hand navigation and generate a new API token using the button that reads Add Key.
We recommend setting both your Token Nickname and your Application Name as the name of the platform you are authorizing for. We also recommend that Application Name specifically be in all capital letters, without spaces.
Important: Ensure that token's permissions for Selling Plan are left set at the default selection: Selling Plan: Read. If permissions are toggled to "None" you will not be able to read Selling Plans from the API.
Use the below endpoint to call for information about product Subscription Programs.
Using Shopifyβs Storefront API, productβs selling plan groups can be pulled. To get only Smartrr selling plan groups, filter by appName and limit to Smartrr. Selling plans can be accessed from the selling plan groups.
To retrieve selling plans using Shopify's Storefront API, you can use a GraphQL query. Below is an example of how you might construct a query to fetch selling plans and their details based on a selling plan group:
Shopify selling plan group documentation: https://shopify.dev/docs/api/storefront/2024-10/objects/SellingPlanGroup#top
Shopify product documentation:
https://shopify.dev/docs/api/storefront/2024-10/queries/product
Subscription Programs are configured in the Subscription Programs tab in the left hand navigation of the Smartrr app.
cache
true/false
Available values : true, false
From the call response, use the data provided in the sellingPlans[ ] array to power the storefront display. Submit the shopifyNumericId value for the field selling_plan in the form POST submission in order to attach a Subscription Group alongside an item added to a customerβs cart.
Be sure to replace <shopify domain> with your store's shopify domain. Note, this is required to be a part of cart workflow and not checkout workflow as Shopify does not support subscriptions within the checkout workflow.
For more information on this POST method, visit Shopify's documentation on Cart API References.
The selling_plan property NEEDS to be provided for any subscription line item that is added to cart. Use the cartLinesAdd mutation from Shopify Storefront API to do this.
Shopify cartlinesAdd documentation: https://shopify.dev/docs/api/storefront/2024-10/mutations/cartLinesAdd#argument-lines
200: OK JSON object of the line items associated with the added items422: Unprocessable Entity Occurs when the exact quantity specified for one of the items can't be added to the cart
Important: The product/variant will need to be enabled for the respective Subscription Program in the Smartrr admin portal. These can be detected with the productIds[ ] and/or variantIds[ ] array.
There are three methods for brands to display the Smartrr's Shopify liquid account portal on a headless shop.
We still recommend completing Smartrr's in-app Setup instructions up to step 3. Smartrr Installation β part 1. Install Snippets onto a dummy theme for developers to see how Smartrr renders the account portal, or if your developers would like to duplicate a piece of liquid functionality to headless.
[Recommended] Forward /account βrelated URLs to your {your-store}.myshopify.com domain.
This is our recommended method as it allows Shopify to continue handling all account actions (Login/Logout/Register/Checkout).
Create an account page on your site using the code found in your Shopify theme customers/account.liquid and use <iframe> to display it. This works for headless shops using React.
Duplicate smartrr-account.liquid in HTML, replacing the liquid code with the corresponding HTML Code. This works for headless shops not using React.
For methods 2 and 3, please follow these additional instructions:
The /customer/auth/session endpoint expects a liquidCustomer object. If the myshopify.com/account page is not used, the data may need to be pulled elsewhere. The customer data can be retrieved from Shopify Storefront API.
Below is the schema for the object.