Skip to content

API Reference

Suzie Hopkins edited this page Sep 16, 2020 · 5 revisions

This guide provides reference information for the Khoros API providers, as well as examples of using, customizing, and creating providers. See the lia-sdk-android Javadoc for additional details.

See our demo application for working examples.

Topics include:

About the utility methods

The utility methods on LiSDKManager are used for app initialization and user authentication. See Initializing the SDK for initialization examples. See Authenticating a user for details about user authentication.

Utility method index

Initialization methods

initialize(Context, LiAppCredentials): void

Since 1.3.0

Initializes the SDK. If the initialization is successful getInstance() will return an initialized SDK Manager. This function may or may not create a new instance or reinitialize the SDK Manager with subsequent calls.

init(Context, LiAppCredentials): LiSDKManager

Deprecated since v1.3.0 use initialize(Context, LiAppCredentials) instead

Used to initialize the SDK. See an example of initialization in Initializing the SDK.

Returns LiSDKManager

isUserLoggedIn(): boolean

Since 1.1.0

Used to check whether a user is logged in or not.

Returns true iff the user is logged in else `false.

isInitialized(): boolean

Since 1.3.0

Used to check whether the SDK is initialized correctly. Should be used before invoking APIs of the SDK or components which depend on it.

Returns true if the SDK is fully initialized, otherwise false

isEnvironmentInitialized(): boolean

Deprecated since v1.3.0 use isInitialized() instead

Since 1.1.0

Confirms whether or not the SDK is initialized.

Returns a boolean

syncWithCommunity(Context): void

Since 1.2.5

Syncs the default settings of the SDK with the Community. Call this after initialize(Context, LiAppCredentials), but before any REST call made to the community. See an example in Initializing the SDK. This call is not required in Community Android SDK versions prior to 1.2.5. Before 1.2.5, synching occurred as part of initialization.

Authentication methods

initLoginFlow(Context): void

Initializes a login flow using Lithium Registration. Takes context as a parameter.

initLoginFlow(Context, String): void

Initializes a login flow using LithiumSSO. Takes context and the SSO token generated using the instructions in

logout(Context): void

Logs the current user out of the community and flushes the authentication state.

About the API providers

When using the Community Android SDK, you can use our Support UI or you can build your own Community integration.

To help you build your own Community experience, we supply a set of API providers on LiClientManager. These providers bundle lower-level APIs along with additional logic to get and set data in Community. The providers themselves do not supply user interface devices; the providers are convenience methods to support your app development.

The providers fall into the following general categories:

Each provider returns a data model. The models provide GET and POST calls to use the data returned from the provider.

Our API providers are designed to meet the general needs of a Community integration. If our API providers don't meet your needs, you can create your own using our custom API providers, which provide the flexibility of using custom LiQL queries and request bodies. Our API providers support the Blog and Forum conversation styles. You can also customize our API providers to use custom filter and sort clauses.

Note: All providers respect the permissions assigned to the user in context based on their role(s) in Community.

Building the client request

Every client requires a set of parameters, including the Android context. Each time you call a client, first instantiate LiClientRequestParams using the getContext() method specific to the client you're calling. Next, you build the client request (LiClient) using the LiClientManager provider, always passing liClientRequestParams.

Here are a couple of examples.

To get the latest messages from the community:

LiClientRequestParams liClientRequestParams = new LiClientRequestParams.LiMessagesClientRequestParams(getContext());
LiClient client = LiClientManager.getMessagesClient(liClientRequestParams);

To get messages from a particular board:

LiClientRequestParams liClientRequestParams = new LiClientRequestParams.LiMessagesByBoardIdClientRequestParams(getContext(), selectedBoardId);
LiClient client = LiClientManager.getMessagesByBoardIdClient(liClientRequestParams);

Remember that each client has a specific LiClientRequestParams method that matches the provider name. For example, getMessagesClient(liClientRequestParams) uses LiMessagesClientRequestParams(Context context) and getMessagesByBoardIdClient(liClientRequestParams) uses LiMessagesByBoardIdClientRequestParams(getContext(), selectedBoardId).

API provider index

Below is the list of API general providers included with the Community Android SDK liak-core package, including descriptions of the providers and the data model each returns. See the lia-core Javadoc for details about each model. See Creating custom API providers for details about our custom providers.

  • Category and Board providers
    • getBoardsByDepthClient(LiClientRequestParams)
    • getCategoryBoardsClient(LiClientRequestParams)
    • getCategoryClient(LiClientRequestParams)
  • Image providers
    • getUploadImageClient(LiClientRequestParams)
  • Message providers
    • getCreateMessageClient(LiClientRequestParams)
    • getCreateReplyClient(LiClientRequestParams)
    • getFloatedMessagesClient(LiClientRequestParams)
    • getMessageClient(LiClientRequestParams)
    • getMessageDeleteClient(LiClientRequestParams)
    • getMessagesByBoardIdClient(LiClientRequestParams)
    • getMessagesByIdsClient(LiClientRequestParams)
    • getMessagesClient(LiClientRequestParams)
    • getRepliesClient(LiClientRequestParams)
  • Message Action providers
    • getAcceptSolutionClient(LiClientRequestParams)
    • getKudoClient(LiClientRequestParams)
    • getMarkMessagePostClient(LiClientRequestParams)
    • getMarkTopicPostClient(LiClientRequestParams)
    • getMarkMessagesPostClient(LiClientRequestParams)
    • getReportAbuseClient(LiClientRequestParams)
    • getSubscriptionDeleteClient(LiClientRequestParams)
    • getSubscriptionPostClient(LiClientRequestParams)
    • getUnKudoClient(LiClientRequestParams)
  • Search providers
    • getSearchClient(LiClientRequestParams)
  • User providers
    • getCreateUserClient(LiClientRequestParams)
    • getUpdateUserClient(LiClientRequestParams)
    • getUserDetailsClient(LiClientRequestParams)
    • getUserMessagesClient(LiClientRequestParams)
    • getUserSubscriptionsClient(LiClientRequestParams)
  • Custom providers
    • getGenericLiqlGetClient(LiClientRequestParams)
    • getGenericPostClient(LiClientRequestParams)
    • getGenericPutClient(LiClientRequestParams)
    • getGenericQueryParamsGetClient(LiClientRequestParams)

Category and Board providers

getBoardsByDepthClient(LiClientRequestParams)

Fetches boards at a specific depth in the Community Structure hierarchy.

Create parameters with LiBoardsByDepthClientRequestParams(Context context, int depth). Takes context and depth as parameters.

Returns LiBrowse

getCategoryBoardsClient(LiClientRequestParams)

Fetches a list of boards for a given category, along with board and category details.

Create request parameters with LiCategoryBoardsClientRequestParams(Context context, String categoryId). Takes context and categoryId.

Returns LiBrowse

getCategoryClient(LiClientRequestParams)

Fetches category details available to the current user. It selects from nodes where node_type is equal to a category. This method respects the Hide from Lists and Menus settings in Community Admin.

Create request parameters with LiCategoryClientRequestParams(Context context). Takes context as a parameter.

Returns LiBrowse

Image providers

getUploadImageClient(LiClientRequestParams)

Uploads an image to Community on behalf of the current user into the user's public album.

Create parameters with LiUploadImageClientRequestParams(Context context, String title, String description, String imageName, String path). Takes context, description, title, imageName, and path (to the image) as parameters. Note that the image filename (imageName) and absolute path (path) parameter values must be the same.

Uses LiUploadImageModel to build request body. The model is converted to a JsonObject, which is then used in the POST call.

Message providers

getCreateMessageClient(LiClientRequestParams)

Creates a new message.

Create parameters with LiCreateMessageClientRequestParams(Context context, String subject, String body, String boardId, String imageId, String imageName). Pass the subject and body of the message and the ID of the board in which to post the message. If you are creating a message with an image, the image ID and image name are also required.

Uses LiPostMessageModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

getCreateReplyClient(LiClientRequestParams)

Creates a reply to a message.

Create parameters with LiCreateReplyClientRequestParams(Context context, String body, Long messageId, String imageId, String imageName). Takes context, body (the reply text), and the messageId (of the parent message). If you are creating a message with an image, the image ID and image name are also required.

Uses LiReplyMessageModel to build request body. The model is converted to a JsonObject, which is then used in the POST call.

getFloatedMessagesClient(LiClientRequestParams)

Fetches all messages floated (or "pinned") to the top of the specified board.

Create parameters with LiFloatedMessagesClientRequestParams(Context context, String boardId, String scope). Takes context, boardId, and scope as parameters.

The supported value for scope is local, which retrieves messages the current user has floated to the top of the specified board.

Returns LiFloatedMessageModel

getMessageClient(LiClientRequestParams)

Fetches details of the specified message.

Create parameters with LiMessageClientRequestParams(Context context, Long messageId). Takes context and messageId as parameters.

Returns LiMessage

getMessageDeleteClient(LiClientRequestParams)

Deletes the specified message

Create parameters with LiMessageDeleteClientRequestParams. Takes context and messageId as parameters.

Returns LiClient

getMessagesByBoardIdClient(LiClientRequestParams)

Fetches all messages on to the specified board.

Create parameters with LiMessagesByBoardIdClientRequestParams(Context context, String boardId). Takes context and boardId as parameters.

Returns LiMessage

getMessagesByIdsClient(LiClientRequestParams)

Fetches details for the specified set of messages.

Create parameters with LiMessagesByIdsClientRequestParams(Context context, Set messageIds). Takes context and messageIds as parameters. Pass the message IDs as a set.

Returns LiMessage

getMessagesClient(LiClientRequestParams)

Fetches a list of all the messages for the user in context.

Create parameters with LiMessagesClientRequestParams(Context context). Takes context as a parameter.

getRepliesClient(LiClientRequestParams)

Fetches details of child messages (replies or comments, and nested replies and comments) of the specified parent message.

Create parameters with LiRepliesClientRequestParams(Context context, Long parentId). Takes context and parentId as parameters.

Returns LiMessage

Message Action providers

getAcceptSolutionClient(LiClientRequestParams)

Marks the specified message as an accepted solution on behalf of the current user.

Create parameters with LiAcceptSolutionClientRequestParams(Context context, Long messageId). Takes context and messageId as parameters. Pass the messageId of the message to accept as a solution.

Uses LiAcceptSolution to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

getKudoClient(LiClientRequestParams)

Kudos the specified message on behalf of the current user.

Create parameters with LiKudoClientRequestParams(Context context, String messageId). Takes context and messageId as parameters. Pass the messageId of the message to kudo.

Uses LiPostKudoModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

getMarkMessagePostClient(LiClientRequestParams)

Added 1.1.0

Mark a single message as read or unread.

Create parameters with LiMarkMessageParams(Context context, String userId, String messageId, boolean markUnread). Takes context, userId, messageId, and markUnread as parameters.

Uses the LiMarkMessageModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

getMarkTopicPostClient(LiClientRequestParams)

Added 1.1.0

Marks a topic message and all its replies as read or unread. Compare this to getMarkMessagesPostClient(LiClientRequestParams), which marks individual messages (not necessarily in the same thread) as read or unread.

Create parameters with LiMarkTopicParams(Context context, String userId, String topicId, boolean markUnread). Takes context, userId, topicId, and markUnread as parameters.

Uses the LiMarkTopicModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

getMarkMessagesPostClient(LiClientRequestParams)

Added 1.1.0

Marks a set of messages (not necessarily in the same thread) as read or unread. Compare this to getMarkTopicPostClient(LiClientRequestParams).

Create parameters with LiMarkMessagesParams(Context context, String userId, String messageIds, boolean markUnread).

Uses the LiMarkMessagesModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

getReportAbuseClient(LiClientRequestParams)

Added 1.0.2

Creates an abuse report on the specified message.

Create parameters with LiReportAbuseClientRequestParams(Context context, String messageId, String userId, String body). Takes context, messageId, userId (the user reporting abuse), and body as parameters.

Uses the LiMarkAbuseModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

Returns LiClient

getSubscriptionDeleteClient(LiClientRequestParams)

Deletes the specified subscription.

Create parameters with LiDeleteSubscriptionParams(Context context, String subscriptionId). Takes context and subscriptionId as parameters.

getSubscriptionPostClient(LiClientRequestParams)

Added 1.0.1

Create a subscription to the specified target (a board or message).

Create parameters with one of the following:

LiPostSubscriptionParams(Context context, LiBaseModel target). Takes context and target as parameters. target is the LiBaseModel for subscription target -- a message or board. If LiBaseModel is not available, pass the target ID and target type using the constructor below.

Added 1.2.0

LiPostSubscriptionParams(Context context, String targetId, String targetType). Takes context, targetId, and targetType as parameters. Use this constructor if you do not have LiBaseModel available. The targetId is either a meessage ID or a board ID. The targetType is either message or board.

getUnKudoClient(LiClientRequestParams)

Removes kudos on the specified message on behalf of the current user.

Create parameters with LiUnKudoClientRequestParams(Context context, String messageId). Take context and messageId as parameters. Pass the messageId of the message to unkudo.

Uses LiPostKudoModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

Search providers

getSearchClient(LiClientRequestParams)

Performs a keyword search in Community.

Create request parameters with LiSearchClientRequestParams(Context context, String query). Takes context and the search text (passed as query), where query is compared against the body and subject of the message.

Returns LiMessage

User providers

getCreateUserClient(LiClientRequestParams)

Added 1.1.0.

Creates a new user account.

Create parameters with LiCreateUserParams(Context context, String email, String login). Takes context, email, and login as parameters.

Uses LiCreateUpdateUserModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call.

getUpdateUserClient(LiClientRequestParams)

Added 1.1.0

Updates an existing user. Create parameters with LiUpdateUserParams(Context context). Takes context as a parameter.

Uses LiCreateUpdateUserModel to build the request body. The model is converted to a JsonObject, which is then used in the POST call. You can update the avatar, biography, cover image, email, first name, last name, and login.

getUserDetailsClient(LiClientRequestParams)

Fetches details about the specified user.

Create request parameters with LiUserDetailsClientRequestParams(Context context, String userId). Takes context and userId as parameters.

Returns LiUser

getUserMessagesClient(LiClientRequestParams)

Fetches blog and forum messages posted by the specified author up to a specified depth.

Create request parameters with LiUserMessagesClientRequestParams(Context context, Long authorId, String depth). Takes context, authorId, and depth as parameters. Depth is the location of the message in the thread where 0 equals the topic message, 1 is a first-level reply, and so on.

Both blog and forum messages are returned by default, unless you have limited the discussion styles supported in your Community Android SDK instance to a single discussion style in Community Style > System > API Apps.

Returns LiMessage

getUserSubscriptionsClient(LiClientRequestParams)

Fetches a list of all Community subscriptions set by the current user.

Create request parameters with LiUserSubscriptionsClientRequestParams(Context context). Takes context as a parameter.

Returns LiSubscriptions

About the data models

There are pre-defined data models for getting data and creating a request body. Below are the details of different models.

GET Models

Model Description
LiBrowse This maps to the Community node in the community. It is used to store details of categories or boards in the community. getBrowseClient and getCategoryClient both use this model.
LiFloatedMessageModel This model maps to the Community API v2 floated_messages resource. It is used to store information of pinned messages.
LiMessage This model maps to the Community API v2 messages resource. This model is used for storing message details, posting messages, retrieving messages, and search. getSearchClient, getUserMessagesClient, getMessagesClient(), getMessageClient, getRepliesClient, and getMessagesByIdsClient use this model.
LiSearch This model provides a one-to-one mapping with the LiMessage model within search results.
LiSubscriptions This model maps to the Community API v2 subscriptions resource. This is used to store details of all the messages a user is subscribed to.
LiUser This model maps to the Community API v2 users resource. It is used to store all details of a user.
LiUserContext This model maps to the Community API v2 user_context resource. It stores information regarding user permissions, such as whether a user can read messages, reply to messages, kudo messages, and accept a message as a solution.

POST/PUT Models

Model Description
LiAcceptSolutionModel This model is used as the request body for accepting a message as a solution.
LiReportAbuseModel This model is used as the request body for reporting a message as inappropriate.
LiMarkMessageModel This model is used as the request body for marking a message as read or unread.
LiMarkMessagesModel This model is used as the request body for marking multiple messages as read or unread.
LiPostKudoModel This model is used as the request body for kudoing a message.
LiPostMessageModel This model is used as the request body for posting a message.
LiReplyMessageModel This model is used as the request body for replying to a message.
LiSubscriptionPostModel This model is used as the request body for subscribing to a message.
LiMarkTopicModel This model is used as the request body for marking a topic message and all of its replies as read or unread.
LiUploadImageModel This model is used as the request body for uploading an image to the community.

Example: Mapping a GET response to a model

This example shows how to map a GET response to a model. It maps the response to the LiMessage model.

LiClientManager clientManager = LiClientManager.getInstance();
LiClient articlesClient = clientManager.getArticlesClient();
articlesClient.processAsync(new LiAsyncRequestCallback<LiGetClientResponse>() {

    @Override
    public void onSuccess(LiBaseRestRequest request, final LiGetClientResponse articlesResponse) {

     // Considering list of response to have single element only
     // Getting the response as a list
     List<LiBaseModel> response = articlesResponse.getResponse();
     // Getting an element from the list
     LiBaseModel clientResponseModel = response.get(0);
     // Casting to LiMessage model
     final LiMessage item = ((LiBaseMessageModel) clientResponseModel).getLiMessage();

    }
    @Override
    public void onError(Exception exception) {

        //Do something if the request fails

    }
};

Using the API providers

Our providers are initialized using LiClientManager. You'll initialize them differently depending on whether you're making a synchronous or asynchronous request. The following examples show both synchronous and asynchronous requests to the getMessagesCilent(liClientRequestParams) provider.

Example: Making a synchronous request with an API provider

This example calls the getMessagesCilent() provider using a synchronous request (a request that must be done in the same thread).

LiClientRequestParams liClientRequestParams = new LiClientRequestParams.LiMessagesClientRequestParams(context);

LiClientManager clientManager = LiClientManager.getInstance();
LiClient articlesClient = clientManager.getMessagesCilent(liClientRequestParams);
LiBaseResponse response = articlesClient.processSync();

Example: Making an asynchronous request with an API provider

This example calls the getMessagesCilent() provider using an asynchronous request (a request that must be done in a separate thread).

LiClientRequestParams liClientRequestParams = new LiClientRequestParams.LiMessagesClientRequestParams(getContext());

LiClientManager clientManager = LiClientManager.getInstance();
LiClient articlesClient = clientManager.getMessagesCilent(liClientRequestParams);
articlesClient.processAsync(new LiAsyncRequestCallback<LiGetClientResponse>() {

    @Override
    public void onSuccess(LiBaseRestRequest request, final LiGetClientResponse articlesResponse) {
        //Do something on success
        List<LiBaseModel> response = articlesResponse.getResponse();

        // If we want it to show on UI as a Toast we can do this
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(activity, String.valueOf(response.size()), Toast.LENGTH_SHORT).show();
        });

    }
    @Override
    public void onError(Exception exception) {
      //Do something if the request fails
    }
};

Customizing queries in the API providers

getGenericQueryParamsGetClient(LiClientRequestParams)

For the GET client API providers, you can create a custom WHERE clause, ORDER BY, and LIMIT parameters to LIQL queries used in our API providers. We include a list of customizable clients later in this section.

Create parameters using LiGenericQueryParamsClientRequestParams(Context context, LiQueryRequestParams liQueryRequestParams).

The following example makes a synchronous GET call, setting custom filtering, ordering, and response limits to the default LI_ARTICLES_CLIENT. Notice in the example where we specify for which client we are specifying the custom query request parameters.

builder.setClient(LiClientManager.Client.LI_ARTICLES_CLIENT);

Here's is the full example:

//LiQueryRequestParams is the class where we specify the WHERE clause , ORDER BY, and LIMIT parameters
LiQueryRequestParams.Builder builder = LiQueryRequestParams.getBuilder();
	//Specifies which client to use.
        builder.setClient(LiClientManager.Client.LI_ARTICLES_CLIENT);
	//Sets the limit
        builder.setLimit(10);
	// Orders by POST_TIME in ascending order
        Ordering ordering = new Ordering(Ordering.Articles.POST_TIME, Ordering.Order.ASC);
	// Sets "where DEPTH = 1" as the WHERE clause
        Clause clause = new Clause(QuerySetting.LiWhereClause.EQUALS, WhereClause.Articles.DEPTH, "1", "AND");
        WhereClause whereClause = new WhereClause();
        whereClause.addClause(clause);
        builder.setOrdering(ordering);
        builder.setWhereClause(whereClause);
        LiQueryRequestParams queryRequestParams = builder.build();

LiClientRequestParams liClientRequestParams =
        new LiClientRequestParams.LiGenericQueryParamsClientRequestParams(getContext(), queryRequestParams);

//Passing the request parameters
LiClient genericClient =
                LiClientManager.getInstance().getGenericQueryParamsGetClient(liClientRequestParams);

//Making sync call
 genericClient.processSync();

These are the clients you can customize:

  • LI_MESSAGES_CLIENT,
  • LI_MESSAGES_BY_BOARD_ID_CLIENT,
  • LI_SDK_SETTINGS_CLIENT,
  • LI_USER_SUBSCRIPTIONS_CLIENT,
  • LI_CATEGORY_BOARDS_CLIENT,
  • LI_BOARDS_BY_DEPTH_CLIENT,
  • LI_REPLIES_CLIENT,
  • LI_SEARCH_CLIENT,
  • LI_USER_MESSAGES_CLIENT,
  • LI_USER_DETAILS_CLIENT,
  • LI_MESSAGE_CLIENT,
  • LI_FLOATED_MESSAGES_CLIENT,
  • LI_MESSAGES_BY_ID_CLIENT,
  • LI_KUDO_CLIENT,
  • LI_UNKUDO_CLIENT,
  • LI_ACCEPT_SOLUTION_CLIENT,
  • LI_CREATE_MESSAGE_CLIENT,
  • LI_CREATE_REPLY_CLIENT,
  • LI_UPLOAD_IMAGE_CLIENT,
  • LI_MARK_ABUSE_CLIENT,
  • LI_DEVICE_ID_FETCH_CLIENT,
  • LI_DEVICE_ID_UPDATE_CLIENT,
  • LI_GENERIC_POST_CLIENT,
  • LI_GENERIC_LIQL_CLIENT,
  • LI_GENERIC_QUERY_PARAMS_CLIENT,
  • LI_ARTICLES_CLIENT,
  • LI_SUBSCRIPTION_CLIENT,
  • LI_BROWSE_CLIENT,
  • LI_MESSAGE_CHILDREN_CLIENT,
  • LI_QUESTIONS_CLIENT,
  • LI_CATEGORY_CLIENT,
  • LI_CREATE_USER_CLIENT,
  • LI_UPDATE_USER_CLIENT,
  • LI_SUBSCRIPTION_POST_CLIENT,
  • LI_SUBSCRIPTION_DELETE_CLIENT,
  • LI_ARTICLES_BROWSE_CLIENT,
  • LI_MARK_MESSAGE_POST_CLIENT,
  • LI_MARK_MESSAGES_POST_CLIENT,
  • LI_MARK_TOPIC_POST_CLIENT

Creating custom API providers

Our custom GET, POST, and PUT providers enable you to make custom LIQL queries (when using GET) and send custom request bodies (when using POST and PUT).

Note: In the API and this document, the terms custom and generic are synonymous.

Unlike the API providers described earlier in this guide, the custom API providers are not dependent on specific models. Instead, you pass a request body that includes a Community REST API endpoint or LiQL query.

Our custom providers include:

  • getGenericPostClient(LiClientRequestParams)
  • getGenericPutClient(LiClientRequestParams)
  • getGenericLiqlGetClient(LiClientRequestParams)
  • getGenericQueryDeleteClient(LiClientRequestParams)

getGenericPostClient(LiClientRequestParams)

Create parameters with LiGenericPostClientRequestParams(Context context, String path, JsonObject requestBody).

This is a generic POST client that takes the path of a Community API v1 or v2 endpoint as a String and the request body in the form of JsonObject.

Begin path after the /community/2.0/<tenant_ID>/ portion of the URI. This first portion of the URL is generated automatically for you. For example, for the endpoint /community/2.0/<tenant_id>/messages, pass "messages" to LiGenericPostClientRequestParams(Context context, String path, JsonObject requestBody).

The following example posts a new message using the /messages endpoint.

// Build the request body and add message body, type, and ID properties
JsonObject requestBody = new JsonObject();
requestBody.addProperty("body", "this is test reply");
requestBody.addProperty("type", "message");
requestBody.addProperty("Id", "820");

// Build the client request parameters
// Create the custom provider client
// Pass the /messages endpoint and the requestBody created earlier
LiClientRequestParams liClientRequestParams = new LiClientRequestParams.LiGenericPostClientRequestParams(getContext(), "messages", requestBody);
LiClient genericPostClient = LiClientManager.getInstance().getGenericPostClient(liClientRequestParams);

// Make the asynchronous call to the client
genericClient.processAsync(new LiAsyncRequestCallback<LiPostClientResponse>() {
    @Override
    public void onSuccess(LiBaseRestRequest liBaseRestRequest, LiPostClientResponse liPostClientResponse) {
        if (liPostClientResponse.getStatus == 200)
            //If post is successful, do something...
    }
    @Override
    public void onError(Exception e) {
        //Otherwise, if the post is not successful, handle the error
    }
});

getGenericPutClient(LiClientRequestParams)

Create parameters with LiGenericPutClientRequestParams(Context context, String path, JsonObject requestBody).

This is a generic PUT client that takes the path of a Community API v1 or v2 endpoint as a String and the request body in the form of JsonObject.

Begin path after /community/2.0/<tenant_ID>/. The rest of the endpoint path is generated automatically. For example, to use the endpoint /community/2.0/<tenant_id>/messages, pass "messages" to LiGenericPutClientRequestParams(Context context, String path, JsonObject requestBody).

The following example updates an existing message using the /messages endpoint.

// Build the request body and add message body, type, and ID properties
JsonObject requestBody = new JsonObject();
requestBody.addProperty("body", "This is an edited reply body");
requestBody.addProperty("type", "message");
requestBody.addProperty("Id", "820");

// Build the client request parameters
// Create the custom provider client
// Pass the /messages endpoint and the requestBody created earlier
LiClientRequestParams liClientRequestParams = new LiClientRequestParams.LiGenericPutClientRequestParams(getContext(), "messages", requestBody);
LiClient genericPutClient = LiClientManager.getInstance().getGenericPutClient(liClientRequestParams);

// Make the asynchronous call to the client
genericClient.processAsync(new LiAsyncRequestCallback<LiGetClientResponse>() {
    @Override
    public void onSuccess(LiBaseRestRequest liBaseRestRequest, LiPutClientResponse liPutClientResponse) {
        if (liPutClientResponse.getStatus == 200)
            //If post is successful, do something...
    }
    @Override
    public void onError(Exception e) {
        //Otherwise, if the post is not successful, handle the error
    }
});

getGenericLiqlGetClient(LiClientRequestParams)

Create parameters with LiGenericLiqlClientRequestParams(Context context, String liQuery).

Takes context and liQuery as parameters, where liQuery is a LiQL query (e.g. "SELECT subject, body FROM messages LIMIT 1"). This method returns the data in the form of JsonObject.

This example uses a custom GET provider to fetch messages by topic IDs using an asynchronous request.

String newReplyQuery = buildNewReplyQuery(response);

// Create the LiQL query
String newReplyQuery = "SELECT id, user_context.read, parent.id FROM messages WHERE parent.id in ('830', '805')";

// Build the client request parameters
// Create the custom provider client
LiClientRequestParams liClientRequestParams = new LiClientRequestParams.LiGenericLiqlClientRequestParams(getContext(), newReplyQuery);
LiClient genericClient = LiClientManager.getInstance().getGenericLiqlGetClient(liClientRequestParams);

// Make the asynchronous call to the client
genericClient.processAsync(new LiAsyncRequestCallback<LiGetClientResponse>() {
	@Override
	public void onSuccess(LiBaseRestRequest liBaseRestRequest, LiGetClientResponse liGetClientResponse) {

    	//Example of getting data from generic get client
    	JsonArray messageElements = liGetClientResponse.getJsonObject()
                        .get("data").getAsJsonObject().get("items").getAsJsonArray();
    }
    @Override
    public void onError(Exception e) {
        //Handle error
    }
});

getGenericQueryDeleteClient(LiClientRequestParams)

Added 1.1.1

There are three options to create the client request parameters

  • Passing these parameters to the client request parameters object:

    • Context
    • CollectionType (MESSAGE or SUBSCRIPTION)
    • the ID of the collectionType (messageId or subscriptionId)
    • the sub-resource path (e.g. “/kudos”)

    This example removes a kudo from the specified message:

    LiClientRequestParams.LiGenericDeleteClientRequestParams liGenericDeleteClientRequestParams = new
    LiClientRequestParams.LiGenericDeleteClientRequestParams(liClientRequestParams.getContext(), CollectionsType.MESSAGE, messageId, "/kudos");
  • Passing these parameters to the client request parameters object:

    • Context
    • CollectionType (MESSAGE or SUBSCRIPTION)
    • the ID of the collectionType (messageId or subscriptionId)
    • a map of request parameters, for example Map<String, String> requestParams = new HashMap<>(); requestParams.put("delete_message.include_replies", "true");
    LiClientRequestParams.LiGenericDeleteClientRequestParams  liGenericDeleteClientRequestParams = new
    LiClientRequestParams.LiGenericDeleteClientRequestParams(liClientRequestParams.getContext(), CollectionsType.MESSAGE,
    messageId, requestParams);```
  • Passing these parameters to the params object

    • Context
    • CollectionType (MESSAGE or SUBSCRIPTION)
    • the ID of the collectionType (messageId or subscriptionId)
    • the sub-resource path (e.g. “/kudos”)
    • a map of request parameters
LiClientRequestParams.LiGenericDeleteClientRequestParams  liGenericDeleteClientRequestParams = new
LiClientRequestParams.LiGenericDeleteClientRequestParams(liClientRequestParams.getContext(), CollectionsType.MESSAGE, messageId, “/kudos”, requestParams);

Here is a working example.

LiBaseDeleteClient liBaseDeleteClient = (LiBaseDeleteClient) getGenericQueryDeleteClient(liGenericDeleteClientRequestParams);
liBaseDeleteClient.processAsync(new LiAsyncRequestCallback<LiDeleteClientResponse>() {
    @Override
    public void onSuccess(LiBaseRestRequest request, LiDeleteClientResponse response) {
        LiBaseResponse deleteResponse = response.getResponse();
        if (deleteResponse.getHttpCode()  == LiSDKConstants.HTTP_CODE_SUCCESSFUL) {
            // Handle successful delete
        } else {
            // Handle response errors
        }
    }

    @Override
    public void onError(Exception exception) {
            // Handle exceptions
    }
});
Clone this wiki locally