[ Web Proxy ]
URL:
Viewing: https://developers.buffer.com/examples/../examples/../examples/get-post-metrics.html [Back]  [Original]

Get Post Metrics - Buffer API
Buffer API [Buffer API]
Search docs... K
API Status Get API Key
ExamplesGet Post Metrics

Get Post Metrics

Try in Explorer
Copy Page

Fetch performance metrics for a single post. Available for personal workflows and automations only, using a personal API key.

GraphQLcURLNode.jsPythonPHP
Copy Copied!
query GetPostMetrics {
  post(input: { id: "some_post_id" }) {
    id
    text
    channelId
    metrics {
      type
      name
      value
      unit
    }
    metricsUpdatedAt
  }
}
Copy Copied!
curl -X POST 'https://api.buffer.com' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{"query": "query GetPostMetrics {\n  post(input: { id: \"some_post_id\" }) {\n    id\n    text\n    channelId\n    metrics {\n      type\n      name\n      value\n      unit\n    }\n    metricsUpdatedAt\n  }\n}"}'
Copy Copied!
async function getPostMetrics() {
  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 GetPostMetrics {
        post(input: { id: "some_post_id" }) {
          id
          text
          channelId
          metrics {
            type
            name
            value
            unit
          }
          metricsUpdatedAt
        }
      }
      `,
    }),
  });

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

getPostMetrics();
Copy Copied!
import requests

query = """
query GetPostMetrics {
  post(input: { id: "some_post_id" }) {
    id
    text
    channelId
    metrics {
      type
      name
      value
      unit
    }
    metricsUpdatedAt
  }
}
"""

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)
Copy Copied!
<?php

$query = '
query GetPostMetrics {
  post(input: { id: "some_post_id" }) {
    id
    text
    channelId
    metrics {
      type
      name
      value
      unit
    }
    metricsUpdatedAt
  }
}
';

$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);

Web Proxy Viewer  |  New URL  |  Original Page