Getting Started
Buffer's API is built using GraphQL. If you are new to GraphQL, its worth checking out the official GraphQL documentation and tutorial offered by Apollo's to learn the foundations for building for our API.
Register for API Access
To access our API you'll need a Buffer Account and an API token. If you don't have an account yet, you can sign up for one here.
Once you have an Account, you can create an API Key in the API settings of your account.
What the API supports
Your API Key can be used to perform actions against your own Buffer account. Through this we currently support the following operations:
- Post Creation
- Post Retrieval
- Idea Creations
- Account Retrieval
- Organizations Retrieval
- Channels Retrieval
Endpoint
Our GraphQL API can be accessed via the following endpoint:
https://api.buffer.com
If you are looking to make GraphQL calls using postman or any other HTTP request tool, you direct requests to the above endpoint and follow this guide.
Authorization
Requests must be authenticated via the Authorization header. You will need to provide your API token with the correct permissions using the Bearer formatting.
{
"Authorization": "Bearer YOUR_TOKEN"
}
-H 'Authorization: Bearer YOUR_TOKEN'
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
}
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_TOKEN',
]
Making your first request
To make your first request, you can use the following example query to fetch your account and Organization:
query GetOrganizations {
account {
organizations {
id
}
}
}
curl -X POST 'https://api.buffer.com' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{"query": "query GetOrganizations {\n account {\n organizations {\n id\n }\n }\n}"}'
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 GetOrganizations {
account {
organizations {
id
}
}
}
`,
}),
});
const data = await response.json();
console.log(data);
<?php
$query = '
query GetOrganizations {
account {
organizations {
id
}
}
}
';
$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);
Once you have your organizations, you can use the desired organization ID to make further requests to fetch profiles, posts, and other data associated with your organization.