{
  "openapi": "3.1.0",
  "info": {
    "title": "NextPost API & MCP Documentation",
    "version": "1.0.0",
    "description": "Official REST API and Model Context Protocol (MCP) specification for NextPost - Omni-channel Social Media Automation Platform.",
    "contact": {
      "name": "NextPost Developer Support",
      "url": "https://nextpost.id",
      "email": "cs@nextpost.id"
    }
  },
  "servers": [
    {
      "url": "https://api.nextpost.id",
      "description": "Production REST API Server"
    },
    {
      "url": "https://mcp.nextpost.id/mcp",
      "description": "Production MCP (Model Context Protocol) Server"
    }
  ],
  "tags": [
    {
      "name": "MCP Tools",
      "description": "Model Context Protocol tools exposed for AI Agents (Claude Desktop, Cursor, Claude Code, OpenCode, n8n)"
    },
    {
      "name": "Posts",
      "description": "Social media post creation, scheduling, and lifecycle management"
    },
    {
      "name": "Social Accounts",
      "description": "Connected social media accounts, follower stats, and platform quotas"
    },
    {
      "name": "Analytics",
      "description": "Aggregated performance overview, comment metrics, and publishing stats"
    },
    {
      "name": "Subscription & Pricing",
      "description": "Plans, limits, and active subscription management"
    },
    {
      "name": "Credits",
      "description": "AI & operations credit balance and topup history"
    },
    {
      "name": "Webhooks",
      "description": "Event notifications and real-time publish status webhooks"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "npk_API_KEY",
        "description": "API key with npk_ prefix generated from NextPost Dashboard → Setting → API."
      }
    },
    "schemas": {
      "ErrorEnvelope": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "example": "VALIDATION_ERROR"
              },
              "message": {
                "type": "string",
                "example": "Invalid scheduled_at datetime"
              },
              "status": {
                "type": "integer",
                "example": 400
              }
            }
          }
        }
      },
      "Post": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "user_id": {
            "type": "string"
          },
          "content": {
            "type": "string",
            "example": "Excited to launch our new feature! 🚀 #product"
          },
          "platform": {
            "type": "string",
            "enum": [
              "twitter",
              "instagram",
              "facebook",
              "linkedin",
              "tiktok",
              "youtube",
              "threads",
              "pinterest"
            ]
          },
          "social_account_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "scheduled",
              "processing",
              "published",
              "failed",
              "cancelled"
            ]
          },
          "scheduled_at": {
            "type": "string",
            "format": "date-time"
          },
          "published_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "media_urls": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "platform_options": {
            "type": "object"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SocialAccount": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "platform": {
            "type": "string"
          },
          "username": {
            "type": "string"
          },
          "display_name": {
            "type": "string"
          },
          "profile_picture_url": {
            "type": "string",
            "format": "uri"
          },
          "is_connected": {
            "type": "boolean"
          }
        }
      }
    }
  },
  "paths": {
    "/api/posts": {
      "get": {
        "tags": [
          "Posts"
        ],
        "summary": "List user posts",
        "description": "Retrieve a paginated list of social media posts for the authenticated account.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status: draft, scheduled, processing, published, failed, cancelled"
          },
          {
            "name": "platform",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by platform"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            },
            "description": "Page size (max 100)"
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Pagination offset"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with list of posts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Post"
                      }
                    },
                    "meta": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API token"
          }
        }
      },
      "post": {
        "tags": [
          "Posts"
        ],
        "summary": "Create a post",
        "description": "Create a new post for scheduling, immediate publication ('now'), or saving as draft.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "content",
                  "platform",
                  "social_account_id"
                ],
                "properties": {
                  "content": {
                    "type": "string"
                  },
                  "platform": {
                    "type": "string",
                    "enum": [
                      "twitter",
                      "instagram",
                      "facebook",
                      "linkedin",
                      "tiktok",
                      "youtube",
                      "threads",
                      "pinterest"
                    ]
                  },
                  "social_account_id": {
                    "type": "string"
                  },
                  "media_urls": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uri"
                    }
                  },
                  "scheduled_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "draft",
                      "scheduled",
                      "now"
                    ],
                    "default": "scheduled"
                  },
                  "platform_options": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Post successfully created"
          },
          "400": {
            "description": "Validation error"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/api/posts/{id}": {
      "get": {
        "tags": [
          "Posts"
        ],
        "summary": "Get post details",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Post detail object"
          }
        }
      },
      "put": {
        "tags": [
          "Posts"
        ],
        "summary": "Update or reschedule post",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Post updated successfully"
          }
        }
      },
      "delete": {
        "tags": [
          "Posts"
        ],
        "summary": "Delete post",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Post permanently deleted"
          }
        }
      }
    },
    "/api/social-accounts": {
      "get": {
        "tags": [
          "Social Accounts"
        ],
        "summary": "List connected social accounts",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of connected social accounts with status and quotas"
          }
        }
      }
    },
    "/api/analytics/overview": {
      "get": {
        "tags": [
          "Analytics"
        ],
        "summary": "Analytics overview",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregated performance overview"
          }
        }
      }
    },
    "/api/subscription": {
      "get": {
        "tags": [
          "Subscription & Pricing"
        ],
        "summary": "Active user subscription",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current active plan and quota"
          }
        }
      }
    },
    "/api/pricing": {
      "get": {
        "tags": [
          "Subscription & Pricing"
        ],
        "summary": "Public pricing plans",
        "responses": {
          "200": {
            "description": "List of available subscription plans"
          }
        }
      }
    },
    "/api/credits/balance": {
      "get": {
        "tags": [
          "Credits"
        ],
        "summary": "Get credit balance",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Spendable credits and bonus balance"
          }
        }
      }
    }
  }
}