# API requests for pages

**URL:** <https://community.weweb.io/t/api-requests-for-pages/12611>\
**Category:** How do I?\
**Created:** [September 16, 2024, 3:03am UTC](https://community.weweb.io/t/api-requests-for-pages/12611 "2024-09-16T03:03:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AngelOnFira](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/angelonfira/32/9863_2.png) [@AngelOnFira](https://community.weweb.io/u/AngelOnFira)\
**Post date:** [September 16, 2024, 3:03am UTC](https://community.weweb.io/t/api-requests-for-pages/12611/1 "2024-09-16T03:03:33Z")

</div>

I’m trying to find an ergonomic and idiomatic way to load data for a single page.

For context, I have a member page that shows the data of one member. There are many members, so it doesn’t make sense for me to load all of the data for each member into a persistent collection that I then reference for this member. My current thought is that on the member’s page load, I should run a workflow that makes the API call, and stores the result in a variable for use. This seems to be the method referenced in [Two Options for Creating a Dynamic Collection Page](https://docs.weweb.io/pages/dynamic-collection-page.html#two-options-for-creating-a-dynamic-collection-page) as " 1. Bind to variable data".

So my idea of how to accomplish this is:

1. Pass the id of the member in the page URL, say /member/:id
2. In the workflow, make a request to the api, say /member/:id using the param from the page URL
3. Save this to a variable
4. Parts of the member page reference this variable

This seems sensible to me, however, step 2 always fails when I demo loading the page. If i do it with “edit” enabled, it seems to work fine, but if I switch to “preview”, when I navigate to this page, it thinks that the id in the url is “undefined”.

A few extra details about the state:

- The worflow is set to run “on mounted”, so I wonder if it can’t see the URL properly at that point
- I wonder if I’m passing the param in properly to the URL

Any insight would be appreciated!

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [September 16, 2024, 5:55am UTC](https://community.weweb.io/t/api-requests-for-pages/12611/2 "2024-09-16T05:55:05Z")

</div>

if it works in edit mode but not in oreview it may be bacause you are accessing `window` directly. try to replace `window` with `wwLib.getFrontWindow()`.

---

<div class="post-metadata">

**Author:** ![AngelOnFira](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/angelonfira/32/9863_2.png) [@AngelOnFira](https://community.weweb.io/u/AngelOnFira)\
**Post date:** [September 16, 2024, 11:25am UTC](https://community.weweb.io/t/api-requests-for-pages/12611/3 "2024-09-16T11:25:19Z")

</div>

I managed to fix this from moving the workflow from a component on the page with the trigger “on mounted” —\> the page itself with the trigger “on page load (before fetching collections)”. Didn’t know I could put workflows there before.
