Seeking Opinions on Using Section Rendering API for Custom Data Retrieval

Hello Shopify Community,

I hope you’re all doing well.

I have come up with a way to retrieve custom data using the Section Rendering API, but I would like to hear your thoughts on whether there might be any unexpected issues with this approach.

Normally, GET /{locale}/cart.js allows us to retrieve information about the items in the cart. However, it does not support certain fields, such as inventory quantities and metafields.

In our store, we have custom processes that require these fields, so we explored an alternative approach using the Section Rendering API.

Implementation Method

We output cart item information in a section file and retrieve it using the Section Rendering API.

Example: custom-cart-api.liquid

<script id="custom-cart-api" type="application/json">
    [
        {%- for item in cart.items -%}
            {
                "inventory_quantity": {{ item.variant.inventory_quantity }},
                "metafields_key1": "{{ item.variant.metafields.custom.key1 }}",
                etc...
            }
        {%- endfor -%}
    ]
</script>

By retrieving this section using the Section Rendering API, we confirmed that:

  • Custom data such as metafields can be retrieved without issues.
  • Dynamic fields like inventory quantities can also be retrieved in real time.

With this approach, it should be possible to retrieve almost any data that can be output using Liquid, effectively allowing us to use it as a custom API.
While the example focuses on cart items, this method should not be limited to just that and could be applied to other types of data as well.

I would love to hear your thoughts on this approach. Are there any reasons why this might not be recommended? If you have any concerns or better alternatives, please let me know!

Thank you in advance for your feedback.

Hi @user37 using the Section Rendering API to expose data rendered in Liquid definitely works, and in practice I believe many merchants do something similar. However, here are a few things to keep on your radar:

  • Public visibility: those API endpoints are public. If the data you are exposing is sensitive or shouldn’t be queryable by just anyone, you’ll want to guard against exposing it in Liquid.
  • Performance: every request has to render Liquid on Shopify’s side before returning a response and that can add extra overhead. The Section Rendering API is not really intended to act as a general‐purpose data API. If you’re hitting it frequently or returning a large payload, you could run into performance bottlenecks or rate‐limiting issues.
  • Accuracy on real-time: for things like inventory quantities it will be genrally fine, but inventory can change quickly if you have a high volume store.