How to programmatically retrieve section ids for cart rendering in any theme?

Topic summary

A developer is building a Shopify app that uses the Ajax API for add-to-cart functionality and needs to programmatically retrieve theme-specific section IDs for cart rendering across different themes.

Technical Context:

  • The app uses a POST request to /cart/add with FormData
  • Currently appending variant ID, quantity, form type, and UTF-8 encoding
  • Missing the required sections parameter value for bundled cart rendering

Current Status:

  • The question remains unanswered
  • One user has expressed interest in finding a solution
  • No concrete approaches or workarounds have been shared yet

The core challenge is achieving theme-agnostic cart rendering without hardcoding section IDs for each specific theme.

Summarized with AI on November 7. AI used: claude-sonnet-4-5-20250929.

We’re developing a Shopify App that implements the add to cart functionality from the Ajax API.

Is there a way that we can programatically get the required section ids from the theme so that we can make a bundled rendering of the cart, regardless of the theme being used?

const formData = new FormData()

formData.append('id', variantId)
formData.append('quantity', quantity)
formData.append('utf8', '✓')
formData.append('form_type', 'product')
formData.append('sections', sections) // ← This is the value we are missing

await fetch(`/cart/add`, {
    method: 'POST',
    headers: {
         'x-requested-with': 'XMLHttpRequest',
         accept: 'application/javascript',
         'Content-Type': 'multipart/form-data',
    },
    body: JSON.stringify(formData)
});
1 Like

@LucasMRC Have you found a solution for this?