Get Posts With Assets

Fetch a list of posts along with their associated assets (images, videos, etc.) for a specific set of Channel IDs.

query GetPostsWithAssets {
  posts(
    input: {organizationId: "some_organization_id", filter: {status: [sent], channelIds: ["some_channel_id"]}}
  ) {
    edges {
      node {
        id
        text
        createdAt
        channelId
        assets {
          thumbnail
          mimeType
          source
          ... on ImageAsset {
            image {
              altText
              width
              height
            }
          }
        }
      }
    }
  }
}
curl -X POST 'https://api.buffer.com' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{"query": "query GetPostsWithAssets {\n  posts(\n    input: {organizationId: \"some_organization_id\", filter: {status: [sent], channelIds: [\"some_channel_id\"]}}\n  ) {\n    edges {\n      node {\n        id\n        text\n        createdAt\n        channelId\n        assets {\n          thumbnail\n          mimeType\n          source\n          ... on ImageAsset {\n            image {\n              altText\n              width\n              height\n            }\n          }\n        }\n      }\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 GetPostsWithAssets {
      posts(
        input: {organizationId: "some_organization_id", filter: {status: [sent], channelIds: ["some_channel_id"]}}
      ) {
        edges {
          node {
            id
            text
            createdAt
            channelId
            assets {
              thumbnail
              mimeType
              source
              ... on ImageAsset {
                image {
                  altText
                  width
                  height
                }
              }
            }
          }
        }
      }
    }
    `,
  }),
});

const data = await response.json();
console.log(data);
<?php

$query = '
query GetPostsWithAssets {
  posts(
    input: {organizationId: "some_organization_id", filter: {status: [sent], channelIds: ["some_channel_id"]}}
  ) {
    edges {
      node {
        id
        text
        createdAt
        channelId
        assets {
          thumbnail
          mimeType
          source
          ... on ImageAsset {
            image {
              altText
              width
              height
            }
          }
        }
      }
    }
  }
}
';

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