API Status Get API Key

Get Posts With Metrics ⚠️ Experimental

Fetch a paginated list of sent posts together with their performance metrics. When authenticating via OAuth, requires the insights:read scope; personal API keys don't need it.

query GetPostsWithMetrics {
  posts(
    first: 20
    input: {
      organizationId: "some_organization_id"
      filter: { status: [sent], channelIds: ["some_channel_id"] }
    }
  ) {
    edges {
      node {
        id
        text
        dueAt
        channelId
        metrics {
          type
          name
          value
          unit
        }
        metricsUpdatedAt
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}
curl -X POST 'https://api.buffer.com' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{"query": "query GetPostsWithMetrics {\n  posts(\n    first: 20\n    input: {\n      organizationId: \"some_organization_id\"\n      filter: { status: [sent], channelIds: [\"some_channel_id\"] }\n    }\n  ) {\n    edges {\n      node {\n        id\n        text\n        dueAt\n        channelId\n        metrics {\n          type\n          name\n          value\n          unit\n        }\n        metricsUpdatedAt\n      }\n    }\n    pageInfo {\n      endCursor\n      hasNextPage\n    }\n  }\n}"}'
async function getPostsWithMetrics() {
  const response = await fetch('https://api.buffer.com', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_API_KEY',
    },
    body: JSON.stringify({
      query: `
      query GetPostsWithMetrics {
        posts(
          first: 20
          input: {
            organizationId: "some_organization_id"
            filter: { status: [sent], channelIds: ["some_channel_id"] }
          }
        ) {
          edges {
            node {
              id
              text
              dueAt
              channelId
              metrics {
                type
                name
                value
                unit
              }
              metricsUpdatedAt
            }
          }
          pageInfo {
            endCursor
            hasNextPage
          }
        }
      }
      `,
    }),
  });

  const data = await response.json();
  console.log(JSON.stringify(data, null, 2));
}

getPostsWithMetrics();
import requests

query = """
query GetPostsWithMetrics {
  posts(
    first: 20
    input: {
      organizationId: "some_organization_id"
      filter: { status: [sent], channelIds: ["some_channel_id"] }
    }
  ) {
    edges {
      node {
        id
        text
        dueAt
        channelId
        metrics {
          type
          name
          value
          unit
        }
        metricsUpdatedAt
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}
"""

response = requests.post(
    "https://api.buffer.com",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_API_KEY",
    },
    json={
        "query": query,
    },
)

data = response.json()
print(data)
<?php

$query = '
query GetPostsWithMetrics {
  posts(
    first: 20
    input: {
      organizationId: "some_organization_id"
      filter: { status: [sent], channelIds: ["some_channel_id"] }
    }
  ) {
    edges {
      node {
        id
        text
        dueAt
        channelId
        metrics {
          type
          name
          value
          unit
        }
        metricsUpdatedAt
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}
';

$payload = [
    'query' => $query,
];

$ch = curl_init('https://api.buffer.com');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer YOUR_API_KEY',
    ],
    CURLOPT_POSTFIELDS => json_encode($payload),
    CURLOPT_RETURNTRANSFER => true,
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
print_r($data);