josh
November 30, 2023, 6:45am
1
What are you trying to accomplish
I’d like to connect an API data source where the API URL takes various dynamic query string parameters. For example:
www.example.com/api/products?countryCode=GB
I’d like to be able to do something like:
www.example.com/api/products?countryCode=${window.countryCode}
or as all of the variables I need are available in state
, something like:
www.example.com/api/products?countryCode=${state.countryCode}
Code stack you are integrating Builder with
React
Any help would be greatly appreciated.
sheema
November 30, 2023, 8:40am
2
Hey @josh you can use both depending on what you are trying to achieve. Using window will help you if you are using web components or Shopify. Otherwise you can go ahead with state.
You can take a look at our docs and other forum posts for the reference:
If your page design is different for logged-in users, return visitors, query params, etc., here is a solution you'll to render those elements on the client.
Hello, @chinawoodshed , and welcome to the Builder Forum!
Builder is able to access the URL parameters through its ‘state’ object. Since you are working on a page that is connected to Shopify, you can’t edit the previewing URL in the Visual Editor. While making this, you may need to open the Live Preview option and manually add the parameter to the URL until you publish the page.
Example
Let’s say you have a URL parameter called “paidAd” which has a value of “someProduct”.
www.website.com/pag…
josh
November 30, 2023, 8:48am
3
@sheema Thanks for that, I could have sworn I tried that
1 Like
sheema
November 30, 2023, 8:49am
4
Happens to the best of us
This solution does not work for me. using for e.g below URL in API Data URL does not work
https://example.com/products&query.data.Parent_Category_Id=${state.location.query.Parent_Category_ID}
Parent_Category_ID is passed as query param to the page and i am using it to call API . i do not see ${state.location.query.Parent_Category_ID} getting resolved.
josh
January 24, 2024, 9:07am
6
@krishwin Try removing the $