Class Stack

java.lang.Object
com.contentstack.sdk.Stack

public class Stack extends Object
Stack call fetches comprehensive details of a specific stack, It allows multiple users to get content of stack information based on user credentials.
  • Method Details

    • livePreviewQuery

      public Stack livePreviewQuery(Map<String,String> query) throws IOException
      Live Preview lets content managers preview entry content across multiple channels before saving or publishing it to a live website. You can edit an entry and preview the content changes side by side in real-time.

      Note: To be able to preview entry content, developers need to first configure Live Preview for the frontend website and then enable it from the stack settings section in Contentstack. You can set up the base URL and environment across which you want to preview content.

      Parameters:
      query - the query of type HashMap
      Returns:
      stack

      Example

      stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

      HashMap queryMap = new HashMap();

      stack.livePreviewQuery(queryMap)

      Throws:
      IOException - IO Exception
    • contentType

      public ContentType contentType(String contentTypeUid)
      Content type defines the structure or schema of a page or a section of your web or mobile property. To create content for your application, you are required to first create a content type, and then create entries using the content type.
      Parameters:
      contentTypeUid - Enter the unique ID of the content type of which you want to retrieve the entries. The UID is often based on the title of the content type and it is unique across a stack.
      Returns:
      the ContentType

      Example Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); ContentType contentType = stack.contentType("contentTypeUid")

    • asset

      public Asset asset(@NotNull String uid)
      Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use. These files can be attached and used in multiple entries.

      The Get a single asset request fetches the latest version of a specific asset of a particular stack.

      Parameters:
      uid - uid of Asset
      Returns:
      Asset instance Tip: If no version is mentioned, the request will retrieve the latest published version of the asset. To retrieve a specific version, use the version parameter, keep the environment parameter blank, and use the management token instead of the delivery token.

      Example Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); Asset asset = stack.asset("assetUid");

    • assetLibrary

      public AssetLibrary assetLibrary()
      The Get all assets request fetches the list of all the assets of a particular stack. It returns the content of each asset in JSON format.
      Returns:
      AssetLibrary asset library

      Example

      Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); AssetLibrary assets = stack.assetLibrary();

    • getApplicationKey

      public String getApplicationKey()
      Returns apiKey of particular stack
      Returns:
      Stack apiKey
    • getDeliveryToken

      public String getDeliveryToken()
      Returns deliveryToken of particular stack
      Returns:
      deliveryToken delivery token
    • removeHeader

      public void removeHeader(String headerKey)
      Removes Header by key
      Parameters:
      headerKey - of the header

      Example: stack.removeHeader("delivery_token");

    • setHeader

      public void setHeader(@NotNull String headerKey, @NotNull String headerValue)
      Adds header to the stack
      Parameters:
      headerKey - the header key
      headerValue - the header value
    • imageTransform

      public String imageTransform(@NotNull String imageUrl, @NotNull Map<String,Object> parameters)
      Image transform string. This document is a detailed reference to Contentstack Image Delivery API and covers the parameters that you can add to the URL to retrieve, manipulate (or convert) image files and display it to your web or mobile properties.
      Parameters:
      imageUrl - the image url
      parameters - the parameters LinkedHashMap
      Returns:
      the string
    • getContentTypes

      public void getContentTypes(@NotNull org.json.JSONObject params, ContentTypesCallback callback)
      The Get all content types call returns comprehensive information of all the content types available in a particular stack in your account..
      Parameters:
      params - query parameters
      callback - ContentTypesCallback This call returns comprehensive information of all the content types available in a particular stack in your account.
    • sync

      public void sync(SyncResultCallBack syncCallBack)
      The Sync request performs a complete sync of your app data. It returns all the published entries and assets of the specified stack in response. The response also contains a sync token, which you need to store, since this token is used to get subsequent delta
      Parameters:
      syncCallBack - returns callback for sync result.
    • syncPaginationToken

      public void syncPaginationToken(@NotNull String paginationToken, SyncResultCallBack syncCallBack)
      Sync pagination token.
      Parameters:
      paginationToken - If the response is paginated, use the pagination token under this parameter.
      syncCallBack - returns callback for sync result

      If the result of the initial sync (or subsequent sync) contains more than 100 records, the response would be paginated. It provides pagination token in the response. However, you do not have to use the pagination token manually to get the next batch, the SDK does that automatically until the sync is complete. Pagination token can be used in case you want to fetch only selected batches. It is especially useful if the sync process is interrupted midway (due to network issues, etc.). In such cases, this token can be used to restart the sync process from where it was interrupted.

      Example :
      Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); stack.syncPaginationToken("paginationToken)

    • syncToken

      public void syncToken(String syncToken, SyncResultCallBack syncCallBack)
      Sync token.
      Parameters:
      syncToken - Use the sync token that you received in the previous/initial sync under this parameter.
      syncCallBack - returns callback for sync result

      You can use the sync token (that you receive after initial sync) to get the updated content next time. The sync token fetches only the content that was added after your last sync, and the details of the content that was deleted or updated.

      Example :

                                                                                                                                                                                                                                                                                                   Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
                                                                                                                                                                                                                                                                                                   stack.syncToken("syncToken")
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           stack.syncToken(sync_token, new SyncResultCallBack()                                                                                                                                                                                                               ){ }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
    • syncFromDate

      public void syncFromDate(@NotNull Date fromDate, SyncResultCallBack syncCallBack)
      Sync from date.
      Parameters:
      fromDate - Enter the start date for initial sync.
      syncCallBack - Returns callback for sync result.

      You can also initialize sync with entries published after a specific date. To do this, use syncWithDate and specify the start date as its value.

      Example :
      Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); stack.syncFromDate("fromDate")

    • syncContentType

      public void syncContentType(@NotNull String contentType, SyncResultCallBack syncCallBack)
      Sync content type.
      Parameters:
      contentType - Provide uid of your content_type
      syncCallBack - Returns callback for sync result.

      You can also initialize sync with entries of only specific content_type. To do this, use syncContentType and specify the content type uid as its value. However, if you do this, the subsequent syncs will only include the entries of the specified content_type.

      Example :

      stack.syncContentType(String content_type, new SyncResultCallBack()){ }

    • syncLocale

      public void syncLocale(String localeCode, SyncResultCallBack syncCallBack)
      Sync locale.
      Parameters:
      localeCode - Select the required locale code.
      syncCallBack - Returns callback for sync result.

      You can also initialize sync with entries of only specific locales. To do this, use syncLocale and specify the locale code as its value. However, if you do this, the subsequent syncs will only include the entries of the specified locales.

      Example :
      Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); stack.syncContentType(String content_type, new SyncResultCallBack()){ }

    • syncPublishType

      public void syncPublishType(Stack.PublishType publishType, SyncResultCallBack syncCallBack)
      Sync publish type.
      Parameters:
      publishType - Use the type parameter to get a specific type of content like

      (asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, content_type_deleted.)

      syncCallBack - returns callback for sync result.

      Use the type parameter to get a specific type of content. You can pass one of the following values: asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, content_type_deleted. If you do not specify any value, it will bring all published entries and published assets.

      Example :
      Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); * stack.syncPublishType(PublishType)

    • sync

      public void sync(String contentType, Date fromDate, String localeCode, Stack.PublishType publishType, SyncResultCallBack syncCallBack)
      Sync.
      Parameters:
      contentType - your content type id
      fromDate - start date
      localeCode - language as language code
      publishType - type as PublishType
      syncCallBack - Callback

      You can also initialize sync with entries that satisfy multiple parameters. To do this, use syncWith and specify the parameters. However, if you do this, the subsequent syncs will only include the entries of the specified parameters

      Example :