> ## Documentation Index
> Fetch the complete documentation index at: https://developers.scrunch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Query API Quickstart

> Step-by-step walkthrough for your first Scrunch Query API call to fetch weekly brand presence, sentiment, and AI visibility metrics by platform.

### Prerequisites

* A Scrunch workspace
* An API key with **Query** access
* A **brand ID** for the brand you want to query

***

### Call the API

<Tabs>
  <Tab title="cURL">
    <Steps>
      <Step title="Set your API key">
        Get your API key from **Organization Settings → API Keys** and set it as environment variables:

        ```bash theme={null}
        export SCRUNCH_API_KEY="your-api-key-here"
        export SCRUNCH_BRAND_ID="your-brand-id"
        ```
      </Step>

      <Step title="Make your first Query API request">
        This example retrieves **weekly brand presence** for the last 30 days.

        ```bash theme={null}
        curl "https://api.scrunchai.com/v1/$SCRUNCH_BRAND_ID/query?fields=date_week,brand_presence_percentage&start_date=2025-01-01&end_date=2025-01-31" \
          -H "Authorization: Bearer $SCRUNCH_API_KEY" \
          -H "Accept: application/json"
        ```

        **Example output:**

        ```json theme={null}
        {
          "total": 4,
          "limit": 1000,
          "offset": 0,
          "rows": [
            {
              "date_week": "2025-01-06",
              "brand_presence_percentage": 42.1
            },
            {
              "date_week": "2025-01-13",
              "brand_presence_percentage": 47.8
            }
          ]
        }
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Python">
    <Steps>
      <Step title="Install dependencies">
        ```bash theme={null}
        pip install requests pandas
        ```
      </Step>

      <Step title="Create your script">
        ```python theme={null}
        import requests
        import pandas as pd

        API_KEY = "your-api-key"
        BRAND_ID = "your-brand-id"
        BASE_URL = f"https://api.scrunchai.com/v1/{BRAND_ID}/query"

        params = {
            "fields": "date_week,brand_presence_percentage",
            "start_date": "2025-01-01",
            "end_date": "2025-01-31",
        }

        response = requests.get(
            BASE_URL,
            headers={"Authorization": f"Bearer {API_KEY}"},
            params=params,
            timeout=30,
        )
        response.raise_for_status()

        data = response.json()
        df = pd.DataFrame(data)
        print(df)
        ```
      </Step>

      <Step title="Run your code">
        ```bash theme={null}
        python quickstart.py
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="JavaScript / TypeScript">
    <Steps>
      <Step title="Install Axios">
        ```bash theme={null}
        npm install axios
        ```
      </Step>

      <Step title="Create your code">
        ```javascript theme={null}
        import axios from "axios";

        const API_KEY = "your-api-key";
        const BRAND_ID = "your-brand-id";

        async function main() {
          const url = `https://api.scrunchai.com/v1/${BRAND_ID}/query`;

          const response = await axios.get(url, {
            headers: { Authorization: `Bearer ${API_KEY}` },
            params: {
              fields: "date_week,brand_presence_percentage",
              start_date: "2025-01-01",
              end_date: "2025-01-31",
            },
          });

          console.log(response.data.rows);
        }

        main().catch(console.error);
        ```
      </Step>

      <Step title="Run your code">
        ```bash theme={null}
        node quickstart.js
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

***

## Next steps

<CardGroup cols={3}>
  <Card title="Query API overview" icon="chart-line" href="/api-reference/query/overview">
    Learn how fields, dimensions, and metrics work together.
  </Card>

  <Card title="Build dashboards" icon="chart-simple" href="/integrations/looker-studio">
    Send Query data into Looker Studio or your BI tool.
  </Card>

  <Card title="Responses API" icon="file-lines" href="/api-reference/responses/overview">
    Get full answers, citations, and sentiment when you need row-level detail.
  </Card>
</CardGroup>
