How to use Section Rendering API for dynamic collection display?

Shopify Partner
1 0 0

Good evening,

I'm trying to use the Section Rendering API to render the feature collection of the Dawn Theme. I want to change dinamically the collection showed.


I'm trying an approach like this:


var appendToBody = await fetch(`/?sections=featured-collection`).then(response => response.json());


I want to pass to the call the collection name, but I'm not obtaining the correct response.


Case 1:

var appendToBody = await fetch(`/?sections=featured-collection&collection=rings`).then(response => response.json());


In this case I'm obtaining and empty collection.


Case 2:


const params = { collection_handle: 'rings' };


const response = await fetch('/sections/featured-collection',

{ method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' },

body: JSON.stringify(params) });


In this case I'm obtaining a 404 error (resource not found).

What's wrong? I'd apreciate any help.

Thanks in advance.

Replies 0 (0)