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

# Get Social Media Statistics

> Retrieve analytics data for multiple social media accounts. Provides metrics for the last 7 days with comparison to the previous 7 days. Supports filtering by platforms and specific connected accounts

Retrieve analytics data for multiple social media accounts. Provides metrics for the last 7 days with comparison to the previous 7 days. Supports filtering by platforms and specific connected accounts.

```http theme={null}
POST https://services.leadconnectorhq.com/social-media-posting/statistics
```

## Autorización

<ParamField header="Authorization" type="string" required>
  Bearer token generado desde el portal Leadway. Ver [Autenticación](/authentication).
</ParamField>

<ParamField header="Version" type="string" required default="2021-07-28">
  Versión de la API.
</ParamField>

## Query parameters

<ParamField query="locationId" type="string" required default="w37swmmLbA02zgqKPpxITe2">
  Account ID
</ParamField>

## Body

<ParamField body="profileIds" type="string[]" required>
  Array of connected social media account IDs to fetch analytics for. This can be found as 'profileId' in /accounts api.
</ParamField>

<ParamField body="platforms" type="string[]">
  Array of social media platforms to filter analytics by. If not provided, all platforms will be included. NOTE: Linkedin (PAGE only) and Tiktok (BUSINESS only) are supported.
</ParamField>

## Respuestas

<Accordion title="201 - Successfully retrieved analytics data">
  <ResponseField name="results" type="object">
    Analytics data grouped by metrics and platforms

    <Expandable title="propiedades">
      <ResponseField name="dayRange" type="string[]">
        Array of day names for the analytics period
      </ResponseField>

      <ResponseField name="totals" type="object">
        Aggregated metrics totals

        <Expandable title="propiedades">
          <ResponseField name="posts" type="number" />

          <ResponseField name="likes" type="number" />

          <ResponseField name="followers" type="number" />

          <ResponseField name="impressions" type="number" />

          <ResponseField name="comments" type="number" />
        </Expandable>
      </ResponseField>

      <ResponseField name="postPerformance" type="object">
        Post performance metrics over time

        <Expandable title="propiedades">
          <ResponseField name="posts" type="object" />

          <ResponseField name="impressions" type="number[]" />

          <ResponseField name="likes" type="number[]" />

          <ResponseField name="comments" type="number[]" />
        </Expandable>
      </ResponseField>

      <ResponseField name="breakdowns" type="object">
        Detailed breakdowns by metric and platform

        <Expandable title="propiedades">
          <ResponseField name="posts" type="object">
            <Expandable title="propiedades">
              <ResponseField name="total" type="number" />

              <ResponseField name="totalChange" type="number" />

              <ResponseField name="platforms" type="object" />
            </Expandable>
          </ResponseField>

          <ResponseField name="impressions" type="object">
            <Expandable title="propiedades">
              <ResponseField name="total" type="number" />

              <ResponseField name="totalChange" type="number" />

              <ResponseField name="platforms" type="object" />
            </Expandable>
          </ResponseField>

          <ResponseField name="reach" type="object">
            <Expandable title="propiedades">
              <ResponseField name="total" type="number" />

              <ResponseField name="totalChange" type="number" />

              <ResponseField name="platforms" type="object" />
            </Expandable>
          </ResponseField>

          <ResponseField name="engagement" type="object" />
        </Expandable>
      </ResponseField>

      <ResponseField name="platformTotals" type="object">
        Platform-wise totals with time series data

        <Expandable title="propiedades">
          <ResponseField name="impressions" type="object" />

          <ResponseField name="followers" type="object" />

          <ResponseField name="likes" type="object" />
        </Expandable>
      </ResponseField>

      <ResponseField name="demographics" type="object">
        Demographic data breakdown

        <Expandable title="propiedades">
          <ResponseField name="gender" type="object">
            <Expandable title="propiedades">
              <ResponseField name="totals" type="object">
                <Expandable title="propiedades">
                  <ResponseField name="male" type="object" />

                  <ResponseField name="female" type="object" />

                  <ResponseField name="unknown" type="object" />
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="age" type="object">
            <Expandable title="propiedades">
              <ResponseField name="totals" type="object">
                <Expandable title="propiedades">
                  <ResponseField name="13-17" type="number" />

                  <ResponseField name="18-24" type="number" />

                  <ResponseField name="25-34" type="number" />

                  <ResponseField name="35-44" type="number" />

                  <ResponseField name="45-54" type="number" />

                  <ResponseField name="55-64" type="number" />

                  <ResponseField name="65+" type="number" />
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="message" type="string" default="Analytics Built Successfully" />

  <ResponseField name="traceId" type="string" default="42fc8dd8-d55b-475f-944f-9efb90d77564" />

  ```json theme={null}
  {
    "results": {
      "dayRange": [
        "Mon",
        "Tue",
        "Wed",
        "Thu",
        "Fri",
        "Sat",
        "Sun"
      ],
      "totals": {
        "posts": 0,
        "likes": 0,
        "followers": 0,
        "impressions": 0,
        "comments": 0
      },
      "postPerformance": {
        "posts": {
          "google": [
            0,
            0,
            0,
            0,
            0,
            0,
            0
          ]
        },
        "impressions": [
          0,
          0,
          0,
          0,
          0,
          0,
          0
        ],
    // truncado: 136 lineas mas
  }
  ```
</Accordion>

<Accordion title="400 - Bad Request - Occurs when more than 100 accounts are requested or invalid parameters are provided">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="401 - Unauthorized - Invalid or missing authentication credentials">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="422 - Unprocessable Entity - Invalid request body format">
  ```json theme={null}
  {}
  ```
</Accordion>

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST 'https://services.leadconnectorhq.com/social-media-posting/statistics' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "profileIds": [
      "67a5a9aa776c837de4aa5b12"
    ],
    "platforms": [
      "facebook",
      "instagram"
    ]
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/social-media-posting/statistics', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"profileIds": ["67a5a9aa776c837de4aa5b12"], "platforms": ["facebook", "instagram"]}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/social-media-posting/statistics',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"profileIds": ["67a5a9aa776c837de4aa5b12"], "platforms": ["facebook", "instagram"]},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/social-media-posting/statistics');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
          'Version: 2021-07-28',
          'Content-Type: application/json',
      ],
      CURLOPT_POSTFIELDS => json_encode({'profileIds': ['67a5a9aa776c837de4aa5b12'], 'platforms': ['facebook', 'instagram']}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
