# Get All Proposals For DAO

If we want to fetch all proposals for a DAO, we have to follow these steps

* Get <mark style="color:yellow;">Realm id</mark> for the DAO you are interested in<mark style="color:yellow;">.</mark> You can either have it beforehand or search based on DAO name.
* Once we have the <mark style="color:yellow;">realm address</mark>, we will fetch all the associated <mark style="color:yellow;">governance accounts.</mark>
* We will use the <mark style="color:yellow;">\_in</mark>  operator to pass all governance accounts in one call and fetch all the associated proposals.

{% tabs %}
{% tab title="Code" %}

```javascript
// Node doesn't implement fetch so we have to import it
import fetch from "node-fetch";

const SHYFT_API_KEY = 'YOUR-KEY'
async function fetchGraphQL(query, variables = {}, name = "MyQuery") {
  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/?api_key=${SHYFT_API_KEY}`,
    {
      method: "POST",
      body: JSON.stringify({
        query: query,
        variables: variables,
        operationName: name
      })
    }
  );

  return await result.json();
}

async function fetchProposals(governanceAccounts) {

const query = `
  query MyQuery($_in: [String!] = "") {
    GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1(
      where: {governance: {_in: $_in}}
    ) {
      closedAt
      descriptionLink
      draftAt
      executingAt
      executionFlags
      governance
      governingTokenMint
      instructionsCount
      instructionsExecutedCount
      instructionsNextIndex
      lamports
      maxVoteWeight
      name
      noVotesCount
      signatoriesCount
      signatoriesSignedOffCount
      signingOffAt
      state
      tokenOwnerRecord
      voteThreshold
      votingAt
      votingAtSlot
      votingCompletedAt
      yesVotesCount
    }
    GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2(
      where: {governance: {_in: $_in}}
    ) {
      abstainVoteWeight
      closedAt
      denyVoteWeight
      descriptionLink
      draftAt
      executingAt
      executionFlags
      governance
      governingTokenMint
      lamports
      maxVoteWeight
      maxVotingTime
      name
      options
      reserved1
      signatoriesCount
      signatoriesSignedOffCount
      signingOffAt
      startVotingAt
      state
      tokenOwnerRecord
      vetoVoteWeight
      voteThreshold
      voteType
      votingAt
      votingAtSlot
      votingCompletedAt
    }
  }
`;

  const variables = {
    _in: governanceAccounts
  }

  const { errors, data } = await fetchGraphQL(query, variables);

  if (errors) {
    // handle those errors like a pro
    console.error(errors);
  }

  return data;
}

async function fetchGovernanceAccounts(realm) {

  //We are only interested in pubkeys of the governance accounts
  const query = `
    query MyQuery {
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_GovernanceV1(
    where: {realm: {_eq: ${JSON.stringify(realm)}}}
  ) {
    pubkey
  }
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_GovernanceV2(
    where: {realm: {_eq:${JSON.stringify(realm)}}}
  ) {
    pubkey
  }
}
  `;

    const { errors, data } = await fetchGraphQL(query);

    if (errors) {
      // handle those errors like a pro
      console.error(errors);
    }

  //Fetch all governance accounts
  const governanceAccounts = []
  data?.GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_GovernanceV1?.forEach(account => {
      governanceAccounts.push(account.pubkey);
    })

  data?.GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_GovernanceV2?.forEach(account => {
      governanceAccounts.push(account.pubkey);
    })


  return governanceAccounts;
}

//Fetch governance accounts for Grape DAO realm
const govAccounts = await fetchGovernanceAccounts("By2sVGZXwfQq6rAiAM3rNPJ9iQfb5e2QhnF4YjJ4Bip")

//Fetch all proposals for the goverance accounts
const proposals = await fetchProposals(govAccounts);
console.log(proposals);
```

{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1": [],
    "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2": [
      {
        "abstainVoteWeight": null,
        "closedAt": null,
        "denyVoteWeight": 0,
        "descriptionLink": "",
        "draftAt": 1659166149,
        "executingAt": null,
        "executionFlags": 0,
        "governance": "e6Tw228L7G6sHZmSsGq5jkTXPwm8KNuNBvsQrJvN61t",
        "governingTokenMint": "8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA",
        "lamports": 3480000,
        "maxVoteWeight": 102499801530352,
        "maxVotingTime": null,
        "name": "Send Element4ls / Dean the Machine to 3PKhz…6cSNt",
        "options": [
          {
            "label": "Approve",
            "voteWeight": "3934219891938",
            "voteResult": 2,
            "instructionsExecutedCount": 0,
            "instructionsCount": 1,
            "instructionsNextIndex": 1
          }
        ],
        "reserved1": 0,
        "signatoriesCount": 1,
        "signatoriesSignedOffCount": 1,
        "signingOffAt": 1659166152,
        "startVotingAt": null,
        "state": 7,
        "tokenOwnerRecord": "G7xHgK76oZXufXNRJ1efDubbuhNbU2kjbLiFK7BeMDRR",
        "vetoVoteWeight": 0,
        "voteThreshold": {
          "type": 0,
          "value": 5
        },
        "voteType": {
          "type": 0
        },
        "votingAt": 1659166152,
        "votingAtSlot": 143769256,
        "votingCompletedAt": 1659427027
      }
      
      //More responses in the array
      
    ]
  }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shyft.to/solana-indexers/case-studies/solana-governance-realms/get-all-proposals-for-dao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
