Posts

Get Post by ID

Get details for a specific post by ID

Endpoint

GET /posts/:postId

Request

curl https://api.postcore.dev/posts/post_abc123 \
  -H "x-api-key: YOUR_API_KEY"
const response = await fetch(
  `https://api.postcore.dev/posts/${postId}`,
  {
    headers: {
      'x-api-key': process.env.POSTCORE_API_KEY
    }
  }
);

const { post } = await response.json();
console.log(`Post status: ${post.status}`);
import os
import requests

response = requests.get(
    f'https://api.postcore.dev/posts/{post_id}',
    headers={'x-api-key': os.getenv('POSTCORE_API_KEY')}
)

post = response.json()['post']
print(f"Post status: {post['status']}")

Response

{
  "post": {
    "postId": "post_abc123",
    "profileKey": "prof_abc123",
    "platform": "linkedin",
    "content": "Excited to announce our new feature! 🚀",
    "scheduledFor": "2025-01-15T14:00:00Z",
    "createdAt": "2025-01-08T12:00:00Z",
    "publishedAt": "2025-01-15T14:00:12Z",
    "status": "published",
    "platformUrl": "https://linkedin.com/feed/update/urn:li:share:123456789"
  }
}

Status Code: 200 OK

Response Fields

FieldTypeDescription
postIdstringUnique post identifier
profileKeystringAssociated profile
platformstringPlatform name
contentstringPost content
scheduledForstringScheduled publish time
createdAtstringWhen post was created
publishedAtstring | nullWhen post was published
statusstring"pending", "published", or "failed"
platformUrlstring | nullURL to post on platform

Use Cases

Check Publishing Status

Poll a post to see if it's been published:

async function waitForPublish(postId) {
  const maxAttempts = 10;
  const delayMs = 5000; // 5 seconds

  for (let i = 0; i < maxAttempts; i++) {
    const { post } = await fetch(`https://api.postcore.dev/posts/${postId}`, {
      headers: { "x-api-key": apiKey },
    }).then((r) => r.json());

    if (post.status === "published") {
      console.log("Post published!", post.platformUrl);
      return post;
    }

    if (post.status === "failed") {
      console.error("Post failed to publish");
      return post;
    }

    // Still pending, wait and try again
    await new Promise((resolve) => setTimeout(resolve, delayMs));
  }

  throw new Error("Timeout waiting for post to publish");
}

Get Platform URLs After Publishing

const { post } = await fetch(`https://api.postcore.dev/posts/${postId}`, {
  headers: { "x-api-key": apiKey },
}).then((r) => r.json());

if (post.status === "published" && post.platformUrl) {
  // Share the link
  console.log(`View on ${post.platform}: ${post.platformUrl}`);

  // Or display in your UI
  const link = document.createElement("a");
  link.href = post.platformUrl;
  link.textContent = `View on ${post.platform}`;
}

Verify Post Before Deleting

async function deletePostSafely(postId) {
  // First, check the post status
  const { post } = await fetch(`https://api.postcore.dev/posts/${postId}`, {
    headers: { "x-api-key": apiKey },
  }).then((r) => r.json());

  if (post.status === "published") {
    console.error("Cannot delete published post");
    return false;
  }

  if (post.status === "pending") {
    // Safe to delete
    await fetch(`https://api.postcore.dev/posts/${postId}`, {
      method: "DELETE",
      headers: { "x-api-key": apiKey },
    });
    console.log("Post deleted");
    return true;
  }
}

Error Responses

Post Not Found

{
  "error": "POST_NOT_FOUND",
  "message": "Post not found"
}

Status: 404 Not Found

Common causes:

  • Invalid postId
  • Post was deleted
  • Post belongs to a different account
  • Typo in the postId parameter

Invalid API Key

{
  "error": "INVALID_API_KEY",
  "message": "Invalid API key"
}

Status: 401 Unauthorized


Comparison with List Posts

Use CaseBest Endpoint
Get all postsGET /posts
Check one post's statusGET /posts/:postId
Find posts by criteriaGET /posts + filter
Get published URLsGET /posts/:postId
Build a dashboardGET /posts

Generally, use GET /posts/:postId when you already have the post ID and need to check its current state or get the platform URL after publishing.