Skip to content

Create Post

The createPost mutation allows you to create a new post in your Teachify school with the specified properties.

FieldTypeDescription
inputAdminPostInput!Input object containing post creation details
FieldTypeRequiredDescription
titleString!YesPost title
subtitleStringNoPost subtitle
bodyString!YesPost body content
excerptStringNoPost excerpt
slugString!YesURL slug for the post. Must contain only lowercase letters, numbers, and hyphens
accessTypeString!YesAccess type for the post (login_required, paid, public_access)
publishedBooleanNoWhether the post is published. Defaults to false
publishedAtIntNoUnix timestamp when the post should be published
categoryIdStringNoID of category to associate with this post. List the available categories with the postCategories query
tagList[String!]NoTags to associate with this post
noindexBooleanNoWhether to exclude this post from search engine indexing
userIdStringNoID of the user (author) for this post
coverPhotoUrlStringNoURL 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

To set a cover photo, upload the image first and pass the resulting CDN URL as coverPhotoUrl:

  1. Call the uploadImage mutation with the filename and contentType of your image. Allowed extensions: jpg, jpeg, png, gif, webp. It returns an attachmentId and a presigned uploadUrl (valid for 15 minutes).
  2. PUT the image file to the returned uploadUrl.
  3. Call the confirmUpload mutation with that attachmentId. It returns the public imageUrl.
  4. Pass that imageUrl as coverPhotoUrl on createPost or updatePost.

Only CDN URLs returned by confirmUpload are accepted.

type AdminPostCreatePayload {
# Array of error messages, if any occurred during the operation
errors: [String!]
# The created post object, null if operation failed
post: AdminPost
}
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
}
}
{
"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": []
}
}
}
ErrorDescription
Title cannot be emptyThe post title is required
Body cannot be emptyThe post body content is required
Slug already existsThe provided slug is already in use
Invalid access typeThe accessType must be one of: login_required, paid, public_access
Category not foundThe specified category ID does not exist
User not foundThe specified user ID does not exist

For more information about the Teachify Admin API, please refer to the API Overview.