---
title: "Contentstack Delivery Ruby SDK"
description: "Documentation for Ruby Delivery SDK"
url: "https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/ruby/reference"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2025-09-15"
---

# Contentstack Delivery Ruby SDK

## Contentstack - Ruby Delivery SDK

## Ruby SDK for Contentstack's Content Delivery API

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).

## Prerequisites

You need ruby v2.0 or later installed to use the Contentstack Ruby SDK.

## SDK installation and setup

Add the following code to your application's Gemfile and bundle:

gem 'contentstack'

Or you can run this command in your terminal (you might need administrator privileges to perform this installation):

gem install contentstack

## Quickstart in 5 mins

## Initialize SDK

You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK:

@stack = Contentstack::Client.new("api\_key", "delivery\_token", "environment")

Once you have initialized the SDK, you can start getting content in your app  
**For Setting other regions**:

Refer the below code if you want to use the Europe, Azure North America, Azure Europe, GCP North America, or GCP Europe region.

JavaScriptAndroidObjective-C.NetJavaPHPRubyPythonDartSwift  
@stack = Contentstack::Client.new("api\_key", "delivery\_token", "environment",{"region": Contentstack::Region::<<add\_your\_region>>})

**For Setting the Branch:**

If you want to initialize SDK in a particular branch use the code given below:

@stack = Contentstack::Client.<span>new</span>("api\_key", "delivery\_token", "environment",{"branch": "branch"})

**Note:** For Europe, set the region as EU, for Azure North America and Azure Europe, set the region as AZURE\_NA and AZURE\_EU respectively, for GCP North America set the region as GCP\_NA, and for GCP Europe set the region as GCP\_EU.

## Basic Queries

**Get a Single Entry**

To retrieve a single entry from a content type, use the code snippet given below:

@stack = Contentstack::Client.new("api\_key", "delivery\_token", "environment")  
@entries = @stack.content\_type("content\_type\_uid").entry("entry\_uid").fetch

### **Get Multiple Entries**

To retrieve multiple entries of a particular content type, use the code snippet given below:

@stack = Contentstack::Client.new("api\_key", "delivery\_token", "environment")  
@entries = @stack.content\_type("content\_type\_uid").query.fetch

**Note:** By default, the limit for response details per request is 100, with the maximum limit set at 250.

## Paginating Responses

In a single instance, the [Get Multiple Entries](https://www.contentstack.com/docs/developers/dot-net/get-started-with-dot-net-delivery-sdk/#get-multiple-entries) query will **retrieve only the first 100 items** of the specified content type. You can paginate and retrieve the rest of the items in batches using the **skip** and **limit** parameters in subsequent requests.

@stack = Contentstack::Client.new("api\_key", "delivery\_token", "environment")  
@entries = @stack.content\_type('category').query  
           .limit(20)  
           .skip(50)  
           .fetch

## Client

Initialize an instance of ‘Client’

## assets

Retrieves all assets of a stack by default.

## asset

Retrieve a single asset with its UID.

The asset uid

## content_types

This method returns comprehensive information of all the content types of a particular stack in your account.

## content_type

Set the content type of which you want to retrieve the entries

UID of the existing content type

## live_preview_query

For live preview data to be fetched provide query parameter to this function

Query parameter for live preview contents.

## sync

Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates

initializing sync

initializing sync with entries of a specific locale

initializing sync with entries of a specific content type

Use the type parameter to get a specific type of content.Supports 'asset\_published', 'entry\_published', 'asset\_unpublished', 'entry\_unpublished', 'asset\_deleted', 'entry\_deleted', 'content\_type\_deleted'

Fetching the next batch of entries using pagination token

Performing subsequent sync after initial sync

## Client

Stack API key

Stack environment specific delivery token

Stack environment for data to be fetched from

Stack API Key.

Stack Delivery token.

Stack Environment name.

## SyncResult

Represents the result of a sync operation.

## SyncResult

Returns the value of attribute skip.

Returns the value of attribute limit.

Readonly property contains all the Contents

Readonly property for paginating sync

Readonly property to delta sync.

Readonly property to check totalCount

Returns the value of attribute skip.

Returns the value of attribute limit.

Readonly property contains all the Contents

Readonly property for paginating sync

Readonly property to delta sync.

Readonly property to check totalCount

## AssetCollection

Asset class to fetch details of files on Contentstack server.

## fetch

Fetch assets uploaded to the Contentstack.

## AssetCollection

## Asset

Asset class to fetch file details on Conentstack server.

## fetch

Fetch a particular asset using uid.

## Asset

Contentstack Asset UID for this asset

Name of the asset.

URL to fetch/render the asset

Content Type for the asset. image/png, image/jpeg, application/pdf, video/mp4 etc.

Size of the asset.

Array of tags assigned to the asset.

Contentstack Asset UID for this asset

Name of the asset.

URL to fetch/render the asset

Content Type for the asset. image/png, image/jpeg, application/pdf, video/mp4 etc.

Size of the asset.

Array of tags assigned to the asset.

## ContentType

ContentType provides Entry and Query instance.

## fetch

A fetch is used to fetch ContentType details for specific UID.

## entry

Retrieve a single entry with its UID.

## query

A query that is used to query for Entry instance.

## ContentType

## EntryCollection

Returns a new instance of EntryCollection.

## EntryCollection

Returns the value of attribute content\_type.

Returns the value of attribute count.

Returns the value of attribute entries.

Returns the value of attribute schema.

Returns the value of attribute content\_type.

Returns the value of attribute count.

Returns the value of attribute entries.

## Entry

An initializer is responsible for creating Entry object.

## get

Get value for field uid

Field uid for which value to be get.

## only

Specifies an array of 'only' keys in BASE object that would be 'included' in the response.

Array of the 'only' reference keys to be included in response.

Reference field uid for which fields to be included

Array of the 'only' reference keys to be included in response.

## except

Specifies list of field uids that would be 'excluded' from the response.

Array of the 'only' reference keys to be excluded in response.

Reference field uid for which fields to be excluded

Array of the 'only' reference keys to be excluded in response.

## include_content_type

Include object's content\_type in response

## include_reference

Add a constraint that requires a particular reference key details.

Pass reference field that must be included in the response

Pass array of reference fields that must be included in the response

## include_fallback

Include the fallback locale publish content, if specified locale content is not publish.

## include_branch

Include the branch for publish content.

## include_embedded_items

Include Embedded Objects (Entries and Assets) along with entry/entries details.

## fetch

Fetches the latest version of the entries from Contentstack.io content stack

## Entry

Returns the value of attribute uid.

Returns the value of attribute content\_type.

Returns the value of attribute fields.

Returns the value of attribute query.

Returns the value of attribute uid.

Returns the value of attribute content\_type.

Returns the value of attribute fields.

Returns the value of attribute query.

## Query

A class that defines a query that is used to query for Entry instance.

## add_query

Add a custom query against specified key.

Field uid to be constraint on

Value for constraint

## remove_query

Combines all the queries together using AND operator

Field uid to be constraint on

## where

Add a constraint to fetch all entries that contains given value against specified key.

Query hash for equal condition

## not_equal_to

Add a constraint to the query that requires a particular key's entry to be not equal to the provided value.

UID of the field for which query should be executed

The object that must not be equaled.

## contained_in

Add a constraint to the query that requires a particular key's entry to be contained in the provided array.

UID of the field for which query should be executed

The possible values for the key's object

## not_contained_in

Add a constraint to the query that requires a particular key entry's value not be contained in the provided array.

UID of the field for which query should be executed

The possible values for the key's object

## include_reference

Add a constraint that requires a particular reference key details.

Pass reference field that must be included in the response

Pass array of reference fields that must be included in the response

## regex

Add a regular expression constraint for finding string values that match the provided regular expression. This may be slow for large data sets. Example:

The key to be constrained.

The regular expression pattern to match.

Regex options

## and

Combines all the queries together using AND operator

Array of instances of the Query class

## or

Add a constraint to fetch all entries which satisfy any queries.

Array of instances of the Query class

## less_than

Add a constraint to the query that requires a particular key entry to be less than the provided value.

UID of the field

Value used to match or compare

## less_than_or_equal

Add a constraint to the query that requires a particular key entry to be less than or equal to the provided value.

UID of the field

Value used to match or compare

## greater_than

Add a constraint to the query that requires a particular key entry to be greater than the provided value.

UID of the field

Value used to match or compare

## greater_than_or_equal

Add a constraint to the query that requires a particular key entry to be greater than or equal to the provided value.

UID of the field

Value used to match or compare

## limit

A limit on the number of objects to return.

Objects to limit in result set.

## skip

The number of objects to skip before returning any.

Objects to skip in result set.

## ascending

Sort the results in ascending order with the given key. Sort the returned entries in ascending order of the provided key.

The key to order by

## descending

Sort the results in descending order with the given key. Sort the returned entries in descending order of the provided key.

The key to order by

## exists

Add a constraint that requires, a specified key exists in response.

The key to be constrained.

## not_exists

Add a constraint that requires, a specified key does not exists in response.

The key to be constrained.

## only

Specifies an array of 'only' keys in BASE object that would be 'included' in the response.

Array of the 'only' reference keys to be included in response.

Reference field uid for which fields to be included

Array of the 'only' reference keys to be included in response.

## except

Specifies list of field uids that would be 'excluded' from the response.

Array of the 'only' reference keys to be excluded in response.

Reference field uid for which fields to be excluded

Array of the 'only' reference keys to be excluded in response.

## include_count

Retrieve count and data of objects in result.

## tags

Include tags with which to search entries.

Array of tags using which search must be performed

## locale

Get entries from the specified locale.

The locale code of the entry

## include_content_type

Include object's content\_type in response

## include_branch

Include the branch for publish content.

## include_fallback

Include the fallback locale publish content, if specified locale content is not publish.

## include_embedded_items

Include Embedded Objects (Entries and Assets) along with entry/entries details.

## find

Fetches the array of the entries from Contentstack for specific ContentType

## find_one

Execute a Query and get the single matching object

## count

Retrieve only count of entries in result.

## Query

Returns the value of attribute content\_type.

Returns the value of attribute query.

Returns the value of attribute content\_type.

Returns the value of attribute query.