# Get listings for a collection across marketplaces

In order to query active listings for a collection, we would first need a mint list (list of addresses of all NFTs belonging to that collection). We can save it before hand or fetch it through DAS. For this example we will be fetching the data through DAS.

GraphQL API also allows you to add <mark style="color:yellow;">multiple filters</mark>, along with <mark style="color:yellow;">checks for a range of values</mark> for particular fields. Suppose, we are filtering the nftMint, or the owner field, we can check if the <mark style="color:yellow;">nftMint</mark> or <mark style="color:yellow;">owner</mark>, <mark style="color:yellow;">belongs to a range (array) of values</mark> instead of just one particular value.

So to achieve the above objective, we will be requiring two simple steps

* We will get a <mark style="color:yellow;">list of all mint addresses</mark> for a collection using DAS.
* We will then use the array of mint addresses to <mark style="color:yellow;">filter the listing</mark> across the three marketplaces.

{% tabs %}
{% tab title="Code Snippet" %}
{% code overflow="wrap" %}

```typescript
import { Network, ShyftSdk } from '@shyft-to/js';
import { gql, GraphQLClient } from 'graphql-request';

const endpoint = `https://programs.shyft.to/v0/graphql?api_key=YOUR-API-KEY`; //Shyft's gQl endpoint

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
}); //Initialize gQL Client

const shyft = new ShyftSdk({ apiKey: "YOUR-API-KEY", network: Network.Mainnet }); //Initialize Shyft SDK

async function getAllListingsForCollection(collectionAddr:string) {

    const allNftMintsforCollection = await getAllMintsofColl(collectionAddr);
    const query = gql`
    query MyQuery {
        MAGIC_EDEN_V2_SellerTradeStateV2(
          where: {tokenMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          tokenMint
          seller
          buyerPrice
        }
        Tensor_SingleListing(
          where: {nftMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          owner
          nftMint
          price
        }
        SNIPER_MARKET_SOLNFTOrderV1(
          where: {nftMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          nftMint
          price
          owner
        }
      }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
  
}

//MadLads collection address
getAllListingsForCollection('J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w')

async function getAllMintsofColl(collectionAddr:string) {
    //function to get all NFTs mints from a collection
    let page = 1;
    const assets = [];

    while (page > 0) {
      const assetsByGroup = await shyft.rpc.getAssetsByGroup({
        groupKey: 'collection',
        groupValue: collectionAddr,
        page,
        limit: 1000,
      });

      console.log(`fetching ${page} from DAS`);
      assets.push(...assetsByGroup.items);
      page = assetsByGroup.total !== 1000 ? -1 : page + 1;
    }

    console.log('Total NFT ', assets.length);
    const nftAddresses = assets.map((nft) => nft.id);
    return nftAddresses;
}
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  MAGIC_EDEN_V2_SellerTradeStateV2: [
    {
      tokenMint: 'JDZP2FipS7xDsiVYXbtqqywaAz9MkXNSgfWvFe2PL2xA',
      pubkey: 'BcxqyQ7S8ddBWo7EEMgrmFWe9HuQTELvVDyhnrF4cSnm',
      seller: '9k3Ad9uoftGYUo6UZAgEn23aqyQWGKqfycb7a8DVcCCN',
      buyerPrice: 283000000
    }
  ],
  Tensor_SingleListing: [
    {
      owner: '6CEM7ptNH2JRE2Ce2GTfNc7uroxZDghBiRj5DGEsqN7M',
      nftMint: 'JANV72ERRvo4iqEAkeqqr7quPJs9M1bDQj3XQKuJwhdV',
      price: 182400000
    }
  ],
  SNIPER_MARKET_SOLNFTOrderV1: [
    {
      nftMint: 'JArGq4iPvciyS8Ry2Qvp9ZHVHmkak3HMMFfdiZrHpqMo',
      price: 220000000,
      owner: 'FtGiXsW72evEzwQ1KBfMAraUT9WfL3rz3ciFY7yQjti5'
    }
  ]
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You can also use our [<mark style="color:red;">MintList</mark>](https://airdrop.shyft.to/) tool to get a collection's mint list.
{% endhint %}

Please note that, like filtering we can also <mark style="color:yellow;">limit</mark> the number of results we want in the response. In the above case we have limited the listings from each marketplace to 1, however this can be removed to fetch more listings for that particular collection from the marketplaces.
