A number of administrative functions can only be accessed with the Amity Social Cloud APIs
Amity APIs can be used either in Admin or User context. Regardless of whether you are using it as an admin or a user, you will need an access token before you can use the API.
For Administrators who are using our APIs in making server-to-server API calls, you need an Admin Access token to connect to the Amity server.
Refer to Admin API Access Token for the instructions on how to generate the admin access token.
If you want use the Amity Social Cloud APIs as a user, you need to register a session via Session API to retrieve the User Access token. Once you've received the accessToken
, you can use the token to call other API endpoints. Please note that User Access token is subject to the same authorization as the owner of the access token.
User Access token is valid for 30 days. However, it will be invalidated if a different device of the same User ID is registered with Device API
User's access tokens can be revoked via the Revoke API. This API can only be used with an admin access token.
Once you have the appropriate access token, you can now use the token to make API calls.
Our API documentation explains all API endpoints used in Amity Social Cloud. Refer to Amity API documentation for a list of all our Amity Social Cloud Rest APIs.
To tweak the user experience for everyone on your network, you will need to use the Network Settings apis with an Admin Token. These services will enable you to toggle application controls such as:
the ability to mention users
showing all posts instead of only followed posts on the global feed
user privacy modes
To see the full list of supported controls, consult the Network Settings section.
User last activity report helps network administrators view a user's activity by date and timestamp based on read and write actions of the users. This allows the administrator to identify active and inactive users.
Using this report, the administrator can also decide what action to take for these inactive users, such as hard deleting them or sending them a notification.
You need an admin account to generate the user's last activity report.
When you set up the app for the first time in our portal, you will receive an administrator account. Alternatively, you can create an administrator account through the ASC Console.
Step 1: Register the session using the Admin account
Step 2: Get admin cookies
Step 3: Export the user last activity report
You will need admin cookies to get this report.
Step 4: Get the list of user’s last activity report
Depending on the tool you use, you can either query it as a list or export it as a CSV report.
If you have any questions, please contact our technical support at support.asc@amity.co
Our Pre-Hook Event feature has been designed to offer customers increased control over user-generated content, community access, and the moderation of sensitive material. This enhancement not only provides a safer environment for applications but also empowers users to create custom moderation rules tailored to their specific requirements.
The Pre-Hook Event feature delivers a range of functionalities that users can employ to establish a more controlled environment within their applications. By enabling the Pre-Hook Event feature through network settings and adjusting the configuration parameters as needed, users can define custom rules and implement APIs to create custom use cases for enhanced moderation. This may include measures such as denying entrance to specific channels for certain users or modifying messages containing sensitive words before they are sent.
The system is designed to trigger pre-hook events for major available actions. Users can monitor the three response types provided by the APIs (allow, deny, and API timeout) and implement proper error handling measures to manage API error cases, ensuring a seamless user experience.
Please note that this feature is only available for customers who are on the max plan.
To make the most of the Pre-Hook Event feature, follow these steps to implement it in your application:
Enable the Feature: Access your network settings through the pre-hook configuration API and enable the Pre-Hook Event feature. While doing so, adjust the configuration parameters, such as enabled, callbackUrl, and defaultAction, according to your requirements.
Create Custom Rules: Develop custom moderation rules based on your application's specific needs. These rules will help you address unique use cases and strengthen your moderation measures.
Implement APIs: Use the provided APIs to create custom use cases for enhanced moderation. These use cases can include denying entrance to specific channels for certain users, modifying messages containing sensitive words before they are sent, and more.
Monitor API Responses: Keep track of the three response types provided by the APIs: allow, deny, and API timeout. These responses will give you insight into the success or failure of your custom rules and actions. Here are the example of request and response of pre-hook event.
Timeout of the provided pre-hook callback is 3 seconds. If it exceeds the timeout, it will execute the provided default action instead.
Request:
Response:
Error Handling: Ensure that you have a robust error handling mechanism in place to manage API error cases effectively. Proper error handling will contribute to a seamless user experience and prevent potential disruptions.
The following sections explain the components, response handling, and error handling involved in the Pre-Hook Event feature.
The external system's response must include the following components:
HTTP status code = 200
Response object with three possible scenarios:
a. Allow the action without modification: { "action" : "allow" }
b. Allow the action with modification: { "action" : "allow", "data" : { ... } // Modified data object }
c. Deny the action: { "action" : "deny", "message" : "this is an error message" }
Signature key to ensure the security between the server and the client.
If a modified data object is returned, its data schema must match the original one.
The security of the pre-hook events feature is ensured through the use of a signature key, which are crucial components in maintaining the confidentiality and integrity of the communication between the server and the client.
Secret Key
Upon configuring and enabling the pre-hook feature for the first time, a secret key is generated. This secret key is a randomly generated 16-byte hexadecimal string.
The secret key serves as a shared symmetric key between the server and the client, which is used for authentication purposes.
In case the secret key is leaked, it can be regenerated to maintain security.
Only network administrators are allowed to access and update the pre-hook setting and regenerate the secret key.
The secret key is available in the update setting API response only when enabling the feature for the first time or when regenerating the secret key. It is not available in the get setting API or when updating other fields.
Signature Key
The signature key is used to authenticate the payload on the external system.
It is computed using the HMAC Base64 digest of the request body. The HMAC Base64 digest is generated by performing the SHA-256 hash function with the secret key as the HMAC key, the request body as the payload, and digested as a Base64 string. Here's an example of generating a signature key from a secret key:
The signature key is included in the request header, ensuring secure communication between the server and the client.
To verify the signature key on the client side, they could do this by computing the hash with the above method and comparing it with the one in the request header. Here is an example
Example of an HTTP request with a signature key attached:
If the action is "allow", the system continues with the remaining application flow, using either the modified data payload (if provided) or the original payload.
If the action is "deny", the system returns an error to the caller with code 400000 as a BadRequestError:
In cases where the response object doesn't adhere to the specified format, or the request takes longer than 3 seconds, the system executes the following error handling flow:
Log the error with the endpoint URL, response status code, response object (trimmed to 300 characters length), or null if the request times out, and the error reason.
Use the default action (allow or deny) as configured in the setting. If the "deny" action is configured, the system returns an error to the caller with code 500401 as a BusinessError:
If the pre-hook service is unavailable or unresponsive due to reaching maximum capacity or other internal server problems, the system executes the following error handling flow:
Use the default action (allow or deny) as configured in the setting. If the "deny" action is configured, the system returns an error to the caller with code 500000 as a BusinessError:
Once the pre-hook process is completed, the system logs the pre-hook URL, response action, and response duration.
Module | Event | Request Data | Modifiable Response Data | REST API Endpoint |
---|---|---|---|---|
Chat
message.shouldCreate
Message Data
Sender ID
Channel ID
Message Data
POST /api/v5/messages
or /api/v3/messages
message.shouldUpdate
Message Data
Sender ID
Channel ID
Message Data
PUT /api/v5/messages
or /api/v3/messages
message.shouldFlag
Message Data
Sender ID
Flag Count
Message Data
POST /api/v5/messages/{messageId}/flag
or /api/v3/messages/{messageId}/flag
message.shouldUnflag
Message Data
Sender ID
Flag count
Message Data
DELETE /api/v5/messages/{messageId}/unflag
or /api/v3/messages/{messageId}/unflag
channel.shouldCreate
Channel Data
Creator ID
Channel Data
POST /api/v3/channels
or /api/v3/channels/conversation
channel.shouldJoin
Channel ID
User ID
-
POST /api/v3/channels/{channelId}/join
channel.shouldLeave
Channel Data
User ID
Channel Data
DELETE /api/v3/channels/{channelId}/leave
Social
post.shouldCreate
Post Data
Creator ID
Entity ID
Post Data
POST /api/v4/posts
post.shouldUpdate
Post Data
Creator ID
Entity ID
Post Data
PUT /api/v4/posts/{postId}
post.shouldFlag
-
-
POST /api/v3/posts/flag
post.shouldUnFlag
-
-
DELETE /api/v3/posts/unflag
comment.shouldCreate
Comment Data
Creator ID
Post ID
Comment Data
POST /api/v3/comments
comment.shouldUpdate
Comment Data
Creator ID
Post ID
Comment Data
PUT /api/v3/comments
comment.shouldFlag
-
-
POST /api/v3/comments/flag
comment.shouldUnFlag
-
-
DELETE /api/v3/comments/unflag
community.shouldJoin
Community ID
User ID
-
POST /api/v3/communities/{communityId}/join
community.shouldLeave
Community ID
User ID
-
DELETE /api/v3/communities/{communityId}/leave
community.shouldCreate
Community Data
Creator ID
Community Data
POST /api/v3/communities
community.shouldUpdate
Community Data
Creator ID
Community Data
reaction.shouldCreate
-
-
POST /api/v2/reactions
follow.shouldUnfollow
Follow Data
-
DELETE /api/v4/me/following/{userId}
follow.shouldRequest
Follow Data
-
POST /api/v4/me/following/{userId}
Core
user.shouldFlag
-
-
POST /api/v4/me/flags/{userId}
user.shouldUnflag
-
-
DELETE /api/v4/me/flags/{userId}