Did You Know You Can Request Additional Scopes on Demand in Shopify Apps?

Did You Know You Can Request Additional Scopes on Demand in Shopify Apps?

Here’s something I recently discovered: Shopify apps can request additional scopes dynamically using optional scopes. This means you can ask merchants for extra permissions only when they’re about to use a specific feature—not during installation.

For example, imagine your app has multiple functionalities, like managing content, files, and markets. But you also offer a side feature to manage discounts. Merchants don’t need this feature right away, so why request those permissions upfront? Instead, you can make read_discounts and write_discounts optional:

TOML

[access_scopes] 
scopes = "read_content,read_files,read_markets" 
optional_scopes = ["read_discounts", "write_discounts"]Copy code        


How It Works in Practice

Let’s say a merchant installs your app to manage their store content. Later, they discover your app’s discount management feature and decide to enable it. At that moment, you can prompt them to approve the necessary scopes dynamically:


Usage Example:

const response = await shopify.scopes.request(["read_discounts", "write_discounts"]); 
if (response.granted) { 
console.log("Scopes approved. You can now access discounts!"); 
} else { 
console.log("Scopes were not approved."); 
}        

If they approve, your app instantly gains the required permissions, and the merchant can start using the discount feature without needing to reinstall the app. If they decline, your app can gracefully handle the situation by disabling or hiding the feature.

Why This Approach Makes Sense

Optional scopes shine in scenarios like this. Instead of overwhelming merchants during installation with permissions for every possible feature, you request only what’s necessary upfront and handle the rest later.

Here’s why this is a game-changer:

  1. Feature-Based Scoping Permissions like read_discounts are requested only when merchants activate the discount management feature.
  2. Seamless Experience Merchants don’t need to reinstall the app to grant new permissions. Everything happens within the app flow.
  3. Improved Trust By delaying permissions until absolutely needed, you demonstrate transparency and respect for merchant privacy.
  4. Use-Case Flexibility This approach is perfect for apps with modular features or optional premium add-ons. Merchants feel in control of what your app can access.

Final Thoughts

Learning about optional scopes has completely changed how I approach permissions in my Shopify apps. It allows me to design apps that are more flexible and user-friendly. Merchants can start with the core features and expand access as they require, without being bombarded with unnecessary permission requests upfront.

If your app has side features or optional modules, I highly recommend giving optional scopes a try. It’s a simple addition that can have a huge impact on your app’s usability and merchant satisfaction.

Have you implemented optional scopes yet? Let me know how it’s working for you!

Darcy Voutt

Shopify Plus Solution Architect & App Developer

2 个月

Really great callout

要查看或添加评论,请登录

Mohamed El-Ghorfi的更多文章

社区洞察

其他会员也浏览了