ContentType

View as Markdown

ContentType

The 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 first to create a content type and then create entries using the content type.

You can now pass the branch header in the API request to fetch or manage modules located within specific branches of the stack. Additionally, you can also set the include_branch query parameter to true to include the _branch top-level key in the response. This key specifies the unique ID of the branch where the concerned Contentstack module resides.

referenceIncludeGlobalField

The "Get all references of content type" call will fetch all the content types in which a specified content type is referenced.

NoteYou must use either the stack's Management Token or the user Authtoken (anyone is mandatory), along with the stack API key, to make a valid Content Management API request. Read more about authentication. You need to use either the stack's Management Token or the user Authtoken (anyone is mandatory), along with the stack API key, to make a valid Content Management API request

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.referenceIncludeGlobalField().execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

importOverwrite

The "Import a content type" call imports a content type into a stack by uploading a JSON file.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.importOverwrite().execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

fieldVisibilityRule

The "Set Field Visibility Rule for Content Type API request" lets you add Field Visibility Rules to existing content types. These rules allow you to show and hide fields based on the state or value of certain fields.

NameTypeDescription
requestBody (required)JSONObject

The request body.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.fieldVisibilityRule("requestBody").execute();

if (response.isSuccessful) {

    System.out.println(<"Response"> + response)

}

addParam

Sets header for the request.

NameTypeDescription
key (required)String
Query parameter key for the request.
value (required)Object
Query parameter value for the request.
import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

contentType.addParam("key", value);

entry

An entry is a content created using one of the defined content types.

NameTypeDescription
entryUid String

The entry uid.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.entry(entryUid).execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

create

The "Create a content type" call creates a new content type in a particular stack of your Contentstack account.

In the Body section, you need to provide the complete schema of the content type.

NameTypeDescription
body (required)JSONObject

The request body.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.create(body).execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

reference

The "Get all references of content type" call will fetch all the content types in which a specified content type is referenced.

NoteYou must use either the stack's Management Token or the user Authtoken (anyone is mandatory), along with the stack API key, to make a valid Content Management API request. Read more about authentication. You need to use either the stack's Management Token or the user Authtoken (one of them is mandatory), along with the stack API key, to make a valid Content Management API request.

NameTypeDescription
isIncludeGlobalField (required)Boolean

Include Global Field true/false

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.reference(isIncludeGlobalField).execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

imports

The "Import a content type" call imports a content type into a stack by uploading a JSON file.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.imports().execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

export

This call is used to export a specific content type and its schema. The data is exported in JSON format. However, please note that the entries of the specified content type are not exported through this call. The schema of the content type returned will depend on the version number provided.

NoteYou must use either the stack's Management Token or the user Authtoken (one of them is mandatory), along with the stack API key, to make a valid Content Management API request.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.export().execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

find

The "Get all content types" call returns comprehensive information on all the content types available in a particular stack in your account.

NoteYou need to use either the stack's Management Token or the user Authtoken (one of them is mandatory), along with the stack API key, to make a valid Content Management API request.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.find().execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

update

The "Update Content Type" call is used to update the schema of an existing content type.

NoteWhenever you update a content type, it will auto-increment the content type version.

NameTypeDescription
requestBody (required)JSONObject

The request body to update the Alias.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.update(requestBody).execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

fetch

The "Get a single content type" call returns information about a specific content type.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.fetch().execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

delete

The "Delete Content Type" call deletes an existing content type and all the entries within it. When executing the API call, in the URI Parameters section, provide the UID of your content type.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

Call<ResponseBody> response = contentType.delete().execute();

if (response.isSuccessful) {

    System.out.println("Response" + response);

}

removeParam

Set header for the request.

NameTypeDescription
key (required)String

Removes query parameters using the key of the request.

import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

contentType.removeParam("key");

addHeader

Sets header for the request.

NameTypeDescription
key (required)String
Header key for the request.
value (required)Object
Header value for the request.
import contentstack;

Contentstack contentstack = new Contentstack.Builder().build();

ContentType contentType = contentstack.stack().contentType();

contentType.addHeader("key", value)

fetchAsPojo

The fetchAsPojo method fetches a single content type and deserializes the response into a POJO.

import contentstack; 

Contentstack contentstack = new Contentstack.Builder().build();
ContentType contentType = contentstack.stack().contentType(content_type_uid);
Response<ContentTypeResponse> response = contentType.fetchAsPojo().execute();
      if (response.isSuccessful() && response.body() != null) {
          ContentTypeResponse ctResponse = response.body();
          System.out.println("ContentType JSON: " + ctResponse.toString());
          if (ctResponse != null) {
           ContentTypePojo ctPojo = ctResponse.getContentPojo();
           System.out.println(" Content Type UID: " + ctPojo.uid);
           System.out.println(" Content Type Title: " + ctPojo.title);
     }
 }  else {
           System.out.println("Error: " + response.errorBody().string());
}

findAsPojo

The findAsPojo method fetches a list of content types and deserializes them into POJOs.

import contentstack; 

Contentstack contentstack = new Contentstack.Builder().build();
Response<ContentTypesResponse> response = contentstack.stack().contentTypes().findAsPojo().execute();
if (response.isSuccessful() && response.body() != null) {
    ContentTypesResponse ctResponse = response.body();
    List<ContentTypePojo> contentTypes = ctResponse.getContentTypes();
    for (ContentTypePojo ct : contentTypes) {
        System.out.println(" Content Type UID: " + ct.uid);
        System.out.println(" Content Type Title: " + ct.title);
    }
} else {
    System.out.println("Error: " + response.errorBody().string());
}