<p>You probably want to use the &quot;Assets associated with the account addresses&quot; endpoint. You can add query params to the request as per <a href="https://docs.blockfrost.io/#tag/Cardano-Accounts/paths/%7E1accounts%7E1%7Bstake_address%7D%7E1addresses%7E1assets/get" rel="nofollow noreferrer">specification</a>.</p>
<p>E.g. to get 100 items on page 3: <a href="https://docs.blockfrost.io/#tag/Cardano-Accounts/paths/%7E1accounts%7E1%7Bstake_address%7D%7E1addresses%7E1assets/get" rel="nofollow noreferrer">/accounts/{stake_address}/addresses/assets?count=100&amp;page=3</a></p>
<p>Now simply create a loop that increments the <code>page</code> query param until you don't get 100 items in the response.</p>

CC BY-SA 4.0
2022-05-23T09:26:53.580Z
2022-05-23T09:26:53.580Z
eddex
<p>I'm trying to count the assets at a blockfrost api endpoint. It only shows 100 items on a page though. How do you loop through all the pages and extract the asset count? Thanks for any help.</p>
<pre><code>const Http = new XMLHttpRequest(),
        method = &quot;GET&quot;,
        url = 'https://cardano-mainnet.blockfrost.io/api/v0/accounts/stake1';
    
    const PAGE_SIZE = 100 /* 100 is the max Blockfrost page size */
    const stake_address = 'stake1'; 

    Http.open(method, url, true);
    Http.setRequestHeader('project_id', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
    Http.send();
    Http.onreadystatechange = (e) =&gt; {
        if (e.currentTarget.readyState == 4 &amp;&amp; e.currentTarget.status == 200 &amp;&amp; e.currentTarget.responseText != '') {
async function count_assets() {
let total = 0;
try {
                let total = 0;
                let assets = [];

do {
    assets = Http.responseText; 
    total += assets.length;
    page++;
    } while (assets.length == page);
} catch (err) {
    console.log('error', err);
}
return total;
}

count_assets(stake_address).then(assets =&gt; {
console.log(stake_address, 'assets:', assets);
});
            }}
</code></pre>

<api><blockfrost><javascript>
How to loop through multiple pages of blockfrost api in Javascript
# How to loop through multiple pages of blockfrost api in Javascript

(Asked by: username_0 on 2022-05-23)

I'm trying to count the assets at a blockfrost api endpoint. It only shows 100 items on a page though. How do you loop through all the pages and extract the asset count? Thanks for any help.
const Http = new XMLHttpRequest(),
        method = "GET",
        url = 'https://cardano-mainnet.blockfrost.io/api/v0/accounts/stake1';
    
    const PAGE_SIZE = 100 /* 100 is the max Blockfrost page size */
    const stake_address = 'stake1'; 

    Http.open(method, url, true);
    Http.setRequestHeader('project_id', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
    Http.send();
    Http.onreadystatechange = (e) => {
        if (e.currentTarget.readyState == 4 && e.currentTarget.status == 200 && e.currentTarget.responseText != '') {
async function count_assets() {
let total = 0;
try {
                let total = 0;
                let assets = [];

do {
    assets = Http.responseText; 
    total += assets.length;
    page++;
    } while (assets.length == page);
} catch (err) {
    console.log('error', err);
}
return total;
}

count_assets(stake_address).then(assets => {
console.log(stake_address, 'assets:', assets);
});
            }}

**Tags:** api, blockfrost, javascript

---

## 1 answers

### Answer by username_1 on 2022-05-23. Score: 0

You probably want to use the "Assets associated with the account addresses" endpoint. You can add query params to the request as per [specification](https://docs.blockfrost.io/#tag/Cardano-Accounts/paths/%7E1accounts%7E1%7Bstake_address%7D%7E1addresses%7E1assets/get).

E.g. to get 100 items on page 3: [/accounts/{stake\_address}/addresses/assets?count=100&page=3](https://docs.blockfrost.io/#tag/Cardano-Accounts/paths/%7E1accounts%7E1%7Bstake_address%7D%7E1addresses%7E1assets/get)

Now simply create a loop that increments the `page` query param until you don't get 100 items in the response.


---

