Search code examples
jsonapiparameterssilexstoryblok

How do I make an Storyblok-API call with multiple parameters incl. "filter_by"?


So far I have seen, the API allows me to add certain parameters to my calls such as filter_by and sort_by.

This works well for me, but I would like to know how do I use multiple parameters at the same time and using the filter_by parameter.

Currently, I am working with the Silex-Boilerplate, which offers me this function:

options('{"sort_by":"name:asc","is_startpage":false}')

I have tried to pass this JSON as options-parameter:

'{"filter_by":"{"component":"reference"}", "sort_by":"name:asc"}'

But it doesn't seem to work. Are there any suggestions about how the JSON could look like?

Thanks in advance!


Solution

  • As I can see you're already using the options Twig helper which is the right way to go.

    options('{"sort_by":"name:asc","is_startpage":false}')
    

    you can use the filter_by parameter directly using this syntax:

    options('{"sort_by":"name:asc","filter_by[component]":"reference"}')
    

    Also this syntax would be possible:

    getStories('starts_with', 1, 10, 'name:ASC', options('{"filter_by":{"component":"reference"}}'))
    

    this will be mapped directly for the API call by our PHP Client Library. Those requests are also cached in your Silex Boilerplate without any extra effort.