Create Post
createPost
mutation is used to create a new post in a space.
It takes spaceId
and CreatePostInput
as inputs.
Each post has a type which defines the fields of it.
You can use postTypes
query to retrieve the
available post types in your community.
- GraphQL
- JS Client
mapping
field in postType defines the fields of the posts with this type.
It is an array of PostTypeMapping
.
The important attributes of it are key
, type
, and required
.
key
: the name of this field used to identify ittype
: the type of this field can be one ofPostMappingTypeEnum
required
: indicate whether this field is required when creating a post
An example of a postType can be:
This is the post type for discussion. It has 2 required fields, title
and content
.
title
should have a text value but content
can contain html.
It also has a non-required field, previewImageId
, whose type is image.
#
Create a postTo create a post you need to define its post type. We will use the discussion post type mentioned above.
The value of the fields (i.e. title
and content
) is passed in the mappingFields
.
The value should be a valid stringified json object. Typically, in JS you can use JSON.stringify()
.
- GraphQL
- JS Client
#
Reply to PostcreateReply
mutation is used to reply to a post.
It takes postId
and CreatePostInput
as inputs.
For example, we can reply with a comment on the post we created above. The post type of comment is this.
Now we can create a reply using this post type.
- GraphQL
- JS Client
#
Create Post with AttachmentsTo create a post with attachments you have to first upload the attachments using
upload files.
Then you can pass the id
s of the files as attachmentIds
.
- GraphQL
- JS Client
#
Create Post with Embedded ImageTo embed images in the post first you need to upload images.
Then you can use the mediaUrl
and mediaId
of the uploaded images to create the html element below
and embed it in the content of the post.
Then the final code to create the post will be similar to this.
note
Don't forget that you have to use JSON.stringify()
for the value field.
- GraphQL
- JS Client
#
Create Post with Embedded Video(s)To embed videos in the post first you need to upload them.
Then you can use the mediaUrl
and mediaId
of the uploaded images to create the html element below
and embed it in the content of the post.
Then the final code to create the post will be similar to this.
note
Don't forget that you have to use JSON.stringify()
for the value field.
- GraphQL
- JS Client
Similarly, you can use the same approach to embed anything else (e.g. audio) to the posts.
#
Create Post with Embedded LinksYou can embed links in the post, for example, a YouTube video. To do so you have to first use
embed query and provide the link you want to embed.
Then you can create the html below with the id
and url
of the embed and embed it in the content of the post.
Then the final code to create the post will be similar to this.
note
Don't forget that you have to use JSON.stringify()
for the value field.
- GraphQL
- JS Client