Create Post
The createPost mutation allows you to create a new post in your Teachify school with the specified properties.
Input Parameters
Section titled “Input Parameters”| Field | Type | Description |
|---|---|---|
input | AdminPostInput! | Input object containing post creation details |
AdminPostInput Fields
Section titled “AdminPostInput Fields”| Field | Type | Required | Description |
|---|---|---|---|
title | String! | Yes | Post title |
subtitle | String | No | Post subtitle |
body | String! | Yes | Post body content |
excerpt | String | No | Post excerpt |
slug | String! | Yes | URL slug for the post. Must contain only lowercase letters, numbers, and hyphens |
accessType | String! | Yes | Access type for the post (login_required, paid, public_access) |
published | Boolean | No | Whether the post is published. Defaults to false |
publishedAt | Int | No | Unix timestamp when the post should be published |
categoryId | String | No | ID of category to associate with this post. List the available categories with the postCategories query |
tagList | [String!] | No | Tags to associate with this post |
noindex | Boolean | No | Whether to exclude this post from search engine indexing |
userId | String | No | ID of the user (author) for this post |
coverPhotoUrl | String | No | URL to an image to set as the post cover photo. Must be a CDN URL obtained from the image upload flow; other hosts are rejected with UPLOAD-008 |
Cover Photos
Section titled “Cover Photos”To set a cover photo, upload the image first and pass the resulting CDN URL as coverPhotoUrl:
- Call the
uploadImagemutation with thefilenameandcontentTypeof your image. Allowed extensions:jpg,jpeg,png,gif,webp. It returns anattachmentIdand a presigneduploadUrl(valid for 15 minutes). PUTthe image file to the returneduploadUrl.- Call the
confirmUploadmutation with thatattachmentId. It returns the publicimageUrl. - Pass that
imageUrlascoverPhotoUrloncreatePostorupdatePost.
Only CDN URLs returned by confirmUpload are accepted.
Return Type
Section titled “Return Type”type AdminPostCreatePayload { # Array of error messages, if any occurred during the operation errors: [String!]
# The created post object, null if operation failed post: AdminPost}Example
Section titled “Example”mutation CreatePost { createPost(input: { title: "Getting Started with GraphQL" subtitle: "A comprehensive guide for beginners" body: "GraphQL is a query language for APIs..." excerpt: "Learn the basics of GraphQL" slug: "getting-started-with-graphql" accessType: "public_access" published: true tagList: ["graphql", "tutorial", "api"] }) { post { id title subtitle slug accessType published tags } errors }}Sample Response
Section titled “Sample Response”{ "data": { "createPost": { "post": { "id": "post_12345", "title": "Getting Started with GraphQL", "subtitle": "A comprehensive guide for beginners", "slug": "getting-started-with-graphql", "accessType": "public_access", "published": true, "tags": ["graphql", "tutorial", "api"] }, "errors": [] } }}Common Errors
Section titled “Common Errors”| Error | Description |
|---|---|
Title cannot be empty | The post title is required |
Body cannot be empty | The post body content is required |
Slug already exists | The provided slug is already in use |
Invalid access type | The accessType must be one of: login_required, paid, public_access |
Category not found | The specified category ID does not exist |
User not found | The specified user ID does not exist |
Related Resources
Section titled “Related Resources”- Update Post - Update an existing post
- Delete Post - Delete a post
- Post Management - Overview of post operations
For more information about the Teachify Admin API, please refer to the API Overview.