SidechatAPIClient

API client class for making requests to Sidechat's private API. You'll need to authenticate before using most of the methods.

Constructor

new SidechatAPIClient(tokenopt, rootUrl)

Create a new instance of the API client

Parameters:
NameTypeAttributesDescription
tokenSidechatAuthToken<optional>

user bearer token

rootUrlString

custom API root URL for mocking or using other server

Since
  • 2.0.0-alpha.0

Members

apiRoot :String

Root URL for every API request

Type:
  • String
Default Value
  • "https://api.sidechat.lol"

(constant) defaultHeaders :Object

Default headers for every API request

Type:
  • Object

userToken :SidechatAuthToken

User bearer token

Methods

checkEmailVerification()

Check is the user's email is verified.

Since
  • 1.0.0

checkUsername(username) → {Boolean}

Checks if user can set their username to a string

Parameters:
NameTypeDescription
usernameString

string to check

Since
  • 2.3.6
Returns:

whether or not username is valid and unused

Type: 
Boolean

createComment(parentPostID, text, groupID, replyCommentIDopt, topLevelReplyIDopt, assetListopt, disableDMsopt, anonymousopt) → {SidechatPostOrComment}

Creates a comment on a post

Parameters:
NameTypeAttributesDescription
parentPostIDString

alphanumeric ID of post on which this comment is made

textString

text content of comment

groupIDString

alphanumeric ID of group in which the parent post resides

replyCommentIDString<optional>

alphanumeric ID of comment to reply to. Falls back to parentPostID

topLevelReplyIDString<optional>

alphanumeric ID of the top-level comment to reply to. Used only when replying to replies. Falls back to parentPostID

assetListArray.<SidechatSimpleAsset><optional>

list of assets to attach

disableDMsBoolean<optional>

prevent direct messages being sent to comment's author

anonymousBoolean<optional>

whether or not to hide user's name and icon on comment

Since
  • 2.2.0
Returns:

created comment

Type: 
SidechatPostOrComment

createPost(text, groupID, assetListopt, disableDMsopt, disableCommentsopt, anonymousopt) → {SidechatPostOrComment}

Creates a new post in the specified group

Parameters:
NameTypeAttributesDescription
textString

text content of comment

groupIDString

alphanumeric ID of group in which the parent post resides

assetListArray.<SidechatSimpleAsset><optional>

list of assets to attach.

disableDMsBoolean<optional>

prevent direct messages from being sent to post's author

disableCommentsBoolean<optional>

whether or not comments should be disabled on post

anonymousBoolean<optional>

whether or not to hide user's name and icon on post

Since
  • 2.2.0
Returns:

the created post

Type: 
SidechatPostOrComment

deletePostOrComment(postOrCommentID)

Deletes a post or comment that the user created

Parameters:
NameTypeDescription
postOrCommentIDString

alphanumeric ID of post to delete

Since
  • 2.2.0

getAssetLibrary() → {Array.<SidechatLibraryAsset>}

Retrieves the entire accessible asset library. Be warned that as of the time of this documentation, it's a 1.5MB JSON download and this request is very expensive.

Since
  • 2.0.6
Returns:
Type: 
Array.<SidechatLibraryAsset>

getAvailableGroups(onePage) → {Array.<SidechatGroup>}

Gets groups to be displayed on the "Explore Groups" page

Parameters:
NameTypeDescription
onePageBoolean

whether or not results should be returned as a single page

Since
  • 2.0.0-alpha.0
Returns:
Type: 
Array.<SidechatGroup>

getCurrentUser() → {SidechatCurrentUser}

Gets the current authenticated user and a list of the groups of which they are members.

Since
  • 2.1.0
Returns:
Type: 
SidechatCurrentUser

getDMThread(id) → {SidechatDirectThread}

Gets a single direct message thread

Parameters:
NameTypeDescription
idString

alphanumeric ID of the chat to fetch

Since
  • 2.4.4
Returns:
Type: 
SidechatDirectThread

getDMs() → {Array.<SidechatDirectThread>}

Gets a list of the user's direct messages

Since
  • 2.4.4
Returns:
Type: 
Array.<SidechatDirectThread>

getGroupChats()

Retrieves joinable group chats

Since
  • 2.3.5

getGroupMetadata(groupIDopt) → {SidechatGroup}

Gets the metadata of a group from its ID

Parameters:
NameTypeAttributesDescription
groupIDString<optional>

alphanumeric ID of a group to get. Falls back to user's primary group.

Since
  • 2.1.0
Returns:
Type: 
SidechatGroup

getGroupPosts(groupID, category, cursoropt) → {SidechatPostsAndCursor}

Fetches posts from the specified category in a group

Parameters:
NameTypeAttributesDescription
groupIDString

group ID

category"hot" | "recent" | "top"

category to filter posts

cursorSidechatCursorString<optional>

cursor string

Since
  • 1.0.0
Returns:

List of posts and cursor

Type: 
SidechatPostsAndCursor

getPost(postID, includeDeleted) → {SidechatPostOrComment}

Fetches a single post with just its ID

Parameters:
NameTypeDescription
postIDString

ID of post to fetch

includeDeletedBoolean

undocumented

Since
  • 2.3.0
Returns:

post object

Type: 
SidechatPostOrComment

getPostComments(postID) → {Array.<SidechatPostOrComment>}

Get all the commments on a post

Parameters:
NameTypeDescription
postIDString

post ID to get comments for

Since
  • 2.0.0-alpha.0
Returns:

list of comments

Type: 
Array.<SidechatPostOrComment>

getUpdates(groupIDopt)

Get updated status for user and group

Parameters:
NameTypeAttributesDescription
groupIDString<optional>

ID of a specific group to retrieve info from. Falls back to user's primary group.

Since
  • 2.1.0

getUserAndGroup(groupIDopt)

Get updated status for user and group

Parameters:
NameTypeAttributesDescription
groupIDString<optional>

ID of a specific group to retrieve info from. Falls back to user's primary group.

Since
  • 1.0.0
Deprecated
  • since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!

getUserContent(contentType) → {Array.<SidechatPostOrComment>}

Fetches the posts or comments that the user has created

Parameters:
NameTypeDescription
contentType"posts" | "comments"

type of user content to fetch

Since
  • 2.3.5
Returns:

post object

Type: 
Array.<SidechatPostOrComment>

getUserPosts(username) → {Array.<SidechatPostOrComment>}

Fetches a public user's posts

Parameters:
NameTypeDescription
usernameString

username of the user to fetch

Since
  • 2.6.0
Returns:
Type: 
Array.<SidechatPostOrComment>

getUserProfile(username) → {SidechatProfile}

Fetches a public user profile

Parameters:
NameTypeDescription
usernameString

username of the user to fetch

Since
  • 2.6.0
Returns:
Type: 
SidechatProfile

hidePostsFromUser(postID)

Hides posts from user

Parameters:
NameTypeDescription
postIDString

alphanumeric ID of post to hide

Since
  • 2.6.2

joinGroupChat(groupChatID, displayName, emoji, primaryColor, secondaryColor)

Joins a group chat. To mimic the official client, use the user's display name and icon by default.

Parameters:
NameTypeDescription
groupChatIDString

alphanumeric ID of group chat to join

displayNameString

display name to use in chat

emojiString

emoji to use as icon

primaryColorString

hex string of primary color

secondaryColorString

hex string of secondary color

Since
  • 2.3.5

loginViaSMS(phoneNumber)

Initiate the login process with a phone number. Should be followed up with verifySMSCode().

Parameters:
NameTypeDescription
phoneNumberNumber

US phone number (WITHOUT +1) to send verification code to

Since
  • 1.0.0

readActivity(activityID)

Marks an activity item as read

Parameters:
NameTypeDescription
activityIDString

alphanumeric ID of activity object

Since
  • 2.3.2

registerEmail(email)

Initiate the email setup process. Should be followed up with checkEmailVerification().

Parameters:
NameTypeDescription
emailString

school email address to send verification code to

Since
  • 1.0.0

searchAvailableGroups(query) → {Array.<SidechatGroup>}

Searches for new groups based on a query keyword

Parameters:
NameTypeDescription
queryString

the string to search for. This will be encoded, so strings with spaces and special characters are okay.

Since
  • 2.6.0
Returns:
Type: 
Array.<SidechatGroup>

sendDM(chatID, text, clientID, assets, anonymous)

Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.

Parameters:
NameTypeDescription
chatIDString

alphanumeric ID of the chat to send to

textString

text content of message

clientIDString

alphanumeric device ID

assetsArray.<SidechatAsset>

array of assets to send

anonymousBoolean

whether the DM should be sent anonymously

Since
  • 2.4.4

sendRequest(endpoint, methodopt, bodyopt, headersopt, stripHeadersopt)

Run an arbitrary API request using the current client's authentication

Parameters:
NameTypeAttributesDescription
endpointString

API endpoint to request (e.g. "/v1/posts")

method"GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS"<optional>

HTTP method to use

bodyObject<optional>

body to send with the request

headersObject<optional>

custom headers to send with the request

stripHeadersBoolean<optional>

remove the default headers from the request

Since
  • 2.4.9

setAPIRoot(url)

Manually set the root URL for all API requests. This can be used for mocking requests or redirecting them to a different server

Parameters:
NameTypeDescription
urlString

new root URL to set

Since
  • 2.3.9

setAge(age, registrationID)

Set the user's age. If this function succeeds, the user will be authenticated for future requests.

Parameters:
NameTypeDescription
ageNumber

user's age in years

registrationIDString

the registration ID generated by verifySMSCode()

Since
  • 1.0.0

setDeviceID(deviceId)

Set the device ID of the current user

Parameters:
NameTypeDescription
deviceIdString

the device ID to set

Since
  • 1.0.0

setGroupMembership(groupID, isMember)

Joins or leaves a group

Parameters:
NameTypeDescription
groupIDString

alphanumeric ID of group to join or leave

isMemberBoolean

whether or not the user should be a member of the group

Since
  • 2.3.8

setToken(token)

Manually set the currently signed in user's token. Generally try to avoid this and instead either pass a token to the constructor or login automatically through the auth functions

Parameters:
NameTypeDescription
tokenSidechatAuthToken

user bearer token

setUserBio(userID, bio)

Sets the bio text of a user

Parameters:
NameTypeDescription
userIDString

alphanumeric ID of user

bioString

text to set as bio

Since
  • 2.5.6

setUserIcon(userID, emoji, primaryColor, secondaryColor)

Sets the conversation icon of a user

Parameters:
NameTypeDescription
userIDString

alphanumeric ID of user

emojiString

emoji to set as icon

primaryColorString

hex string (including #) of primary color

secondaryColorString

hex string (including #) of secondary color

Since
  • 2.2.1

setUsername(userID, username)

Changes the username of the current user

Parameters:
NameTypeDescription
userIDString

alphanumeric ID of user

usernameString

new username to set

Since
  • 2.3.6

setVote(postID, action)

Upvote or downvote, or unvote a post

Parameters:
NameTypeDescription
postIDString

post ID to vote on

actionSidechatVoteString

whether to upvote, downvote, or reset vote

Since
  • 2.0.0-alpha.0

startDM(text, clientID, postID, anonymous, postContext)

Creates a new direct message thread

Parameters:
NameTypeDescription
textString

text content of message

clientIDString

alphanumeric ID of devide

postIDString

alphanumeric ID of post or comment

anonymousBoolean

whether the DM should be sent anonymously

postContext"feed"

context of post (mostly undocumented, defaults to "feed")

Since
  • 2.4.4

unhidePostsFromAllUsers()

Unhides all posts from all users

Since
  • 2.6.2

uploadAsset(uri, mimeType, nameopt) → {String}

Uploads an asset to AWS S3 for use in posts and comments. Currently photos only

Parameters:
NameTypeAttributesDescription
uriString

URI of the asset to upload

mimeTypeString

mimetype of the asset (e.g. "image/png")

nameString<optional>

filename of the asset

Since
  • 2.5.1
Returns:

URL of the uploaded asset

Type: 
String

verifySMSCode(phoneNumber, code)

Verify the code sent via SMS with loginViaSMS(). If this function succeeds, the user will be authenticated for future requests.

Parameters:
NameTypeDescription
phoneNumberNumber

US phone number (WITHOUT +1) that verification code was sent to

codeString

the verification code

Since
  • 1.0.0

viewPollResults(pollId)

Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.

Parameters:
NameTypeDescription
pollIdString

alphanumeric ID of poll to vote on

Since
  • 2.5.4

voteOnPoll(pollId, choiceIndex)

Votes on a poll attached to a post

Parameters:
NameTypeDescription
pollIdString

alphanumeric ID of poll to vote on

choiceIndexNumber

index of the choice to vote on

Since
  • 2.5.4