SocialPosts

Posts

Posts related to Social

These endpoints allow you to create, read, update and delete posts. Posts are the main content of a social network, can be created by any profile and can receive reactions and comments.

These endpoints support pagination and sorting. Read more about these features here.

The Post model

PropTypeDefault
id
integer
-
title
string
-
body
string
-
tags
Array<string>
-
image
object
-
created
string
-
updated
string
-
_count
object
-

Optional properties

PropTypeDefault
author?
Profile
-
comments?
Array<Comment>
-
reactions?
Array<Reaction>
-

Query parameters

Not all of the properties of a post are returned by default. You can use the following optional query parameters to include additional properties in the response.

PropTypeDefault
_author
boolean
false
_comments
boolean
false
_reactions
boolean
false
Example with all optional query parameters
{
  "data": {
    "id": 0,
    "title": "string",
    "body": "string",
    "tags": ["string"],
    "media": {
      "url": "https://url.com/image.jpg",
      "alt": "string"
    },
    "created": "2022-09-04T08:08:38.830Z",
    "updated": "2022-09-04T08:08:38.830Z",
    "author": {
      "name": "string",
      "email": "user@example.com",
      "bio": "string",
      "avatar": {
        "url": "https://url.com/image.jpg",
        "alt": "string"
      },
      "banner": {
        "url": "https://url.com/image.jpg",
        "alt": "string"
      }
    },
    "reactions": [
      {
        "symbol": "string",
        "count": 0,
        "reactors": ["string"]
      }
    ],
    "comments": [
      {
        "body": "string",
        "replyToId": null, // or number if comment is reply to another comment
        "id": 0,
        "postId": 0,
        "owner": "string",
        "created": "2022-09-04T08:17:59.383Z",
        "author": {
          "name": "string",
          "email": "user@example.com",
          "bio": "string",
          "avatar": {
            "url": "https://url.com/image.jpg",
            "alt": "string"
          },
          "banner": {
            "url": "https://url.com/image.jpg",
            "alt": "string"
          }
        }
      }
    ],
    "_count": {
      "comments": 0,
      "reactions": 0
    }
  },
  "meta": {}
}

Filtering

You can filter based on an entry in the tags array by using the _tag query flag. You may only filter by one tag at a time.

PropTypeDefault
_tag
string
-

An example query filtering for posts with the tag my_tag:

GET/social/posts?_tag=my_tag

All posts

GET/social/posts

Retrieve all posts.

If you want to get all posts by a specific profile, you can use the posts by profile endpoint.

Response
{
  "data": [
    {
      "id": 0,
      "title": "string",
      "body": "string",
      "tags": ["string"],
      "media": {
        "url": "https://url.com/image.jpg",
        "alt": "string"
      },
      "created": "2022-09-04T08:08:38.830Z",
      "updated": "2022-09-04T08:08:38.830Z",
      "_count": {
        "comments": 0,
        "reactions": 0
      }
    },
    {
      "id": 0,
      "title": "string",
      "body": "string",
      "tags": ["string"],
      "media": {
        "url": "https://url.com/image.jpg",
        "alt": "string"
      },
      "created": "2022-09-04T08:08:38.830Z",
      "updated": "2022-09-04T08:08:38.830Z",
      "_count": {
        "comments": 0,
        "reactions": 0
      }
    }
    // ...
  ],
  "meta": {
    "isFirstPage": true,
    "isLastPage": true,
    "currentPage": 1,
    "previousPage": null,
    "nextPage": null,
    "pageCount": 1,
    "totalCount": 2
  }
}

Single post

GET/social/posts/<id>

Retrieve a single post by its id.

Use the _author, _comments and/or _reactions flags to get more data from this request.

Response
{
  "data": {
    "id": 0,
    "title": "string",
    "body": "string",
    "tags": ["string"],
    "media": {
      "url": "https://url.com/image.jpg",
      "alt": "string"
    },
    "created": "2022-09-04T08:08:38.830Z",
    "updated": "2022-09-04T08:08:38.830Z",
    "_count": {
      "comments": 0,
      "reactions": 0
    }
  },
  "meta": {}
}

All posts from following

GET/social/posts/following

Retrieve all posts from profiles that the authenticated user is following.

The data returned is similar to the all posts endpoint and accepts the same optional query flags.


Create post

POST/social/posts

Create a new post. Only the title property is required, but we recommend at least including the body and media properties as well.

Please note that the media.url property must be a fully formed URL that links to a live and publicly accessible image. The API will check the provided URL and if it cannot be accessed publicly you will receive a 400 Bad Request error response.

Request
{
  "title": "string", // Required
  "body": "string", // Optional
  "tags": ["string"], // Optional
  "media": {
    "url": "https://url.com/image.jpg",
    "alt": "string"
  } // Optional
}
Response
{
  "data": {
    "id": 0,
    "title": "string",
    "body": "string",
    "tags": ["string"],
    "media": {
      "url": "https://url.com/image.jpg",
      "alt": "string"
    },
    "created": "2022-09-04T16:21:02.042Z",
    "updated": "2022-09-04T16:21:02.042Z",
    "_count": {
      "comments": 0,
      "reactions": 0
    }
  },
  "meta": {}
}

Update post

PUT/social/posts/<id>

Update a post based on its id. This endpoint returns the updated post.

Please note that the media.url property must be a fully formed URL that links to a live and publicly accessible image. The API will check the provided URL and if it cannot be accessed publicly you will receive a 400 Bad Request error response.

Request
{
  "title": "string",
  "body": "string",
  "tags": ["string"],
  "media": {
    "url": "https://url.com/image.jpg",
    "alt": "string"
  }
}
Response
{
  "data": {
    "id": 0,
    "created": "2022-09-04T16:21:02.044Z",
    "updated": "2022-09-04T16:21:02.044Z",
    "title": "string",
    "body": "string",
    "tags": ["string"],
    "media": {
      "url": "https://url.com/image.jpg",
      "alt": "string"
    },
    "_count": {
      "comments": 0,
      "reactions": 0
    }
  },
  "meta": {}
}

Delete post

DELETE/social/posts/<id>

Delete a post based on its id.

Returns an empty 204 No Content response on success.


React to post

PUT/social/posts/<id>/react/<symbol>

This endpoint allows you to toggle reactions. If the authenticated user has already reacted to the post with the provided symbol, the reaction will be removed. Otherwise, the reaction will be added.

React to a post with a symbol.

Returns the original post id, the symbol reacted with, and an array of all reactions on the post.

The symbol parameter should be an actual emoji. For example, to react to a post with a 👍 emoji, you would use the following endpoint: /social/posts/<id>/react/👍

You do not need to include a body for this request.

Response
{
  "data": {
    "postId": 0,
    "symbol": "string",
    "reactions": [
      {
        "symbol": "string",
        "count": 0,
        "reactors": ["string"]
      }
    ]
  },
  "meta": {}
}

Comment on post

POST/social/posts/<id>/comment

This endpoint allows a comment to be made on a post. The optional replyToId property can be used to link this comment to an existing comment.

Please note, when replying to another comment, that the replyToId property must be a valid comment id. If the comment exists, but is not associated with the post, you will receive a 400 Bad Request error response. Should the comment not exist, you will receive a 404 Not Found error response.

Request
{
  "body": "string", // Required
  "replyToId": 0 // Optional - Only required if replying to another comment
}
Response
{
  "data": {
    "body": "string",
    "replyToId": null, // or replyToId number if provided in request
    "id": 0,
    "postId": 0,
    "owner": "string",
    "created": "2022-09-04T16:29:07.175Z"
  },
  "meta": {}
}

Delete comment from post

DELETE/social/posts/<id>/comment/<comment-id>

Deleting a comment will also delete all replies to that comment.

Delete a comment based on its id.

Returns an empty 204 No Content response on success.


Search posts

GET/social/posts/search?q=<query>

Search for posts by their title or body properties.