Get Post Metrics ⚠️ Experimental
Fetch performance metrics for a single post. When authenticating via OAuth, requires the insights:read scope; personal API keys don't need it.
query GetPostMetrics {
post(input: { id: "some_post_id" }) {
id
text
channelId
metrics {
type
name
value
unit
}
metricsUpdatedAt
}
}
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}"}'
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();
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)
<?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);