Class: Attio::Resources::Attributes Private

Inherits:
Base
  • Object
show all
Defined in:
lib/attio/resources/attributes.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API resource for managing Attio attributes

Attributes define custom fields that can be added to objects and records in your Attio workspace.

Examples:

Listing attributes

client.attributes.list(object: "people")

Creating a custom attribute

client.attributes.create(
  object: "deals",
  data: {
    title: "Deal Stage",
    api_slug: "deal_stage",
    type: "select",
    options: [
      { title: "Lead", value: "lead" },
      { title: "Qualified", value: "qualified" }
    ]
  }
)

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Attio::Resources::Base

Instance Method Details

#create(object:, data:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a custom attribute for an object

Examples:

Create a select attribute

client.attributes.create(
  object: "trips",
  data: {
    title: "Status",
    api_slug: "status",
    type: "select",
    options: [
      { title: "Pending", value: "pending" },
      { title: "Active", value: "active" }
    ]
  }
)

Parameters:

  • object (String)

    The object type or slug

  • data (Hash)

    The attribute configuration

Options Hash (data:):

  • :title (String)

    The display title of the attribute

  • :api_slug (String)

    The API slug for the attribute

  • :type (String)

    The attribute type (text, number, select, date, etc.)

  • :description (String)

    Optional description

  • :is_required (Boolean)

    Whether the attribute is required

  • :is_unique (Boolean)

    Whether the attribute must be unique

  • :is_multiselect (Boolean)

    For select types, whether multiple values are allowed

  • :options (Array<Hash>)

    For select types, the available options

Returns:

  • (Hash)

    The created attribute

Since:

  • 1.0.0



64
65
66
67
68
69
70
71
72
# File 'lib/attio/resources/attributes.rb', line 64

def create(object:, data:)
  validate_object!(object)
  validate_required_hash!(data, "Attribute data")

  # Wrap data in the expected format
  payload = { data: data }

  request(:post, "objects/#{object}/attributes", payload)
end

#create_option(object:, id_or_slug:, data:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new option for a select attribute

Examples:

Create a new option

client.attributes.create_option(
  object: "deals",
  id_or_slug: "deal_stage",
  data: {
    title: "Negotiation",
    value: "negotiation",
    color: "blue"
  }
)

Parameters:

  • object (String)

    The object type or slug

  • id_or_slug (String)

    The attribute ID or API slug

  • data (Hash)

    The option configuration

Options Hash (data:):

  • :title (String)

    The display title of the option

  • :value (String)

    The value of the option

  • :color (String)

    Optional color for the option

  • :order (Integer)

    Optional order for the option

Returns:

  • (Hash)

    The created option

Since:

  • 1.0.0



145
146
147
148
149
150
151
# File 'lib/attio/resources/attributes.rb', line 145

def create_option(object:, id_or_slug:, data:)
  validate_object!(object)
  validate_id_or_slug!(id_or_slug)
  validate_required_hash!(data, "Option data")

  request(:post, "objects/#{object}/attributes/#{id_or_slug}/options", data)
end

#create_status(object:, id_or_slug:, data:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new status for a status attribute

Examples:

Create a new status

client.attributes.create_status(
  object: "deals",
  id_or_slug: "deal_status",
  data: {
    title: "Under Review",
    value: "under_review",
    color: "yellow"
  }
)

Parameters:

  • object (String)

    The object type or slug

  • id_or_slug (String)

    The attribute ID or API slug

  • data (Hash)

    The status configuration

Options Hash (data:):

  • :title (String)

    The display title of the status

  • :value (String)

    The value of the status

  • :color (String)

    Optional color for the status

  • :order (Integer)

    Optional order for the status

Returns:

  • (Hash)

    The created status

Since:

  • 1.0.0



222
223
224
225
226
227
228
# File 'lib/attio/resources/attributes.rb', line 222

def create_status(object:, id_or_slug:, data:)
  validate_object!(object)
  validate_id_or_slug!(id_or_slug)
  validate_required_hash!(data, "Status data")

  request(:post, "objects/#{object}/attributes/#{id_or_slug}/statuses", data)
end

#get(object:, id_or_slug:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



32
33
34
35
36
# File 'lib/attio/resources/attributes.rb', line 32

def get(object:, id_or_slug:)
  validate_object!(object)
  validate_id_or_slug!(id_or_slug)
  request(:get, "objects/#{object}/attributes/#{id_or_slug}")
end

#list(object:, **params) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



27
28
29
30
# File 'lib/attio/resources/attributes.rb', line 27

def list(object:, **params)
  validate_object!(object)
  request(:get, "objects/#{object}/attributes", params)
end

#list_options(object:, id_or_slug:, **params) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List options for a select attribute

Examples:

List options for a select attribute

client.attributes.list_options(
  object: "deals",
  id_or_slug: "deal_stage"
)

Parameters:

  • object (String)

    The object type or slug

  • id_or_slug (String)

    The attribute ID or API slug

  • params (Hash)

    Additional query parameters

Options Hash (**params):

  • :limit (Integer)

    Number of results to return

  • :offset (Integer)

    Number of results to skip

Returns:

  • (Hash)

    The list of attribute options

Since:

  • 1.0.0



119
120
121
122
123
# File 'lib/attio/resources/attributes.rb', line 119

def list_options(object:, id_or_slug:, **params)
  validate_object!(object)
  validate_id_or_slug!(id_or_slug)
  request(:get, "objects/#{object}/attributes/#{id_or_slug}/options", params)
end

#list_statuses(object:, id_or_slug:, **params) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List statuses for a status attribute

Examples:

List statuses for a status attribute

client.attributes.list_statuses(
  object: "deals",
  id_or_slug: "deal_status"
)

Parameters:

  • object (String)

    The object type or slug

  • id_or_slug (String)

    The attribute ID or API slug

  • params (Hash)

    Additional query parameters

Options Hash (**params):

  • :limit (Integer)

    Number of results to return

  • :offset (Integer)

    Number of results to skip

Returns:

  • (Hash)

    The list of attribute statuses

Since:

  • 1.0.0



196
197
198
199
200
# File 'lib/attio/resources/attributes.rb', line 196

def list_statuses(object:, id_or_slug:, **params)
  validate_object!(object)
  validate_id_or_slug!(id_or_slug)
  request(:get, "objects/#{object}/attributes/#{id_or_slug}/statuses", params)
end

#update(object:, id_or_slug:, data:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update an existing attribute

Examples:

Update an attribute's title

client.attributes.update(
  object: "contacts",
  id_or_slug: "status",
  data: {
    title: "Contact Status",
    description: "The current status of the contact"
  }
)

Parameters:

  • object (String)

    The object type or slug

  • id_or_slug (String)

    The attribute ID or API slug

  • data (Hash)

    The attribute configuration updates

Options Hash (data:):

  • :title (String)

    The display title of the attribute

  • :api_slug (String)

    The API slug for the attribute

  • :description (String)

    Optional description

  • :is_required (Boolean)

    Whether the attribute is required

  • :is_unique (Boolean)

    Whether the attribute must be unique

  • :is_multiselect (Boolean)

    For select types, whether multiple values are allowed

Returns:

  • (Hash)

    The updated attribute

Since:

  • 1.0.0



95
96
97
98
99
100
101
102
103
104
# File 'lib/attio/resources/attributes.rb', line 95

def update(object:, id_or_slug:, data:)
  validate_object!(object)
  validate_id_or_slug!(id_or_slug)
  validate_required_hash!(data, "Attribute data")

  # Wrap data in the expected format
  payload = { data: data }

  request(:patch, "objects/#{object}/attributes/#{id_or_slug}", payload)
end

#update_option(object:, id_or_slug:, option:, data:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update an option for a select attribute

Examples:

Update an option's title

client.attributes.update_option(
  object: "deals",
  id_or_slug: "deal_stage",
  option: "negotiation",
  data: {
    title: "In Negotiation",
    color: "orange"
  }
)

Parameters:

  • object (String)

    The object type or slug

  • id_or_slug (String)

    The attribute ID or API slug

  • option (String)

    The option ID or value

  • data (Hash)

    The option configuration updates

Options Hash (data:):

  • :title (String)

    The display title of the option

  • :value (String)

    The value of the option

  • :color (String)

    Optional color for the option

  • :order (Integer)

    Optional order for the option

Returns:

  • (Hash)

    The updated option

Since:

  • 1.0.0



174
175
176
177
178
179
180
181
# File 'lib/attio/resources/attributes.rb', line 174

def update_option(object:, id_or_slug:, option:, data:)
  validate_object!(object)
  validate_id_or_slug!(id_or_slug)
  validate_option_id!(option)
  validate_required_hash!(data, "Option data")

  request(:patch, "objects/#{object}/attributes/#{id_or_slug}/options/#{option}", data)
end

#update_status(object:, id_or_slug:, status:, data:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update a status for a status attribute

Examples:

Update a status's title

client.attributes.update_status(
  object: "deals",
  id_or_slug: "deal_status",
  status: "under_review",
  data: {
    title: "Pending Review",
    color: "orange"
  }
)

Parameters:

  • object (String)

    The object type or slug

  • id_or_slug (String)

    The attribute ID or API slug

  • status (String)

    The status ID or value

  • data (Hash)

    The status configuration updates

Options Hash (data:):

  • :title (String)

    The display title of the status

  • :value (String)

    The value of the status

  • :color (String)

    Optional color for the status

  • :order (Integer)

    Optional order for the status

Returns:

  • (Hash)

    The updated status

Since:

  • 1.0.0



251
252
253
254
255
256
257
258
# File 'lib/attio/resources/attributes.rb', line 251

def update_status(object:, id_or_slug:, status:, data:)
  validate_object!(object)
  validate_id_or_slug!(id_or_slug)
  validate_status_id!(status)
  validate_required_hash!(data, "Status data")

  request(:patch, "objects/#{object}/attributes/#{id_or_slug}/statuses/#{status}", data)
end

#validate_id_or_slug!(id_or_slug) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)

Since:

  • 1.0.0



264
265
266
# File 'lib/attio/resources/attributes.rb', line 264

private def validate_id_or_slug!(id_or_slug)
  raise ArgumentError, "Attribute ID or slug is required" if id_or_slug.nil? || id_or_slug.to_s.strip.empty?
end

#validate_object!(object) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)

Since:

  • 1.0.0



260
261
262
# File 'lib/attio/resources/attributes.rb', line 260

private def validate_object!(object)
  raise ArgumentError, "Object type is required" if object.nil? || object.to_s.strip.empty?
end

#validate_option_id!(option) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)

Since:

  • 1.0.0



268
269
270
# File 'lib/attio/resources/attributes.rb', line 268

private def validate_option_id!(option)
  raise ArgumentError, "Option ID is required" if option.nil? || option.to_s.strip.empty?
end

#validate_status_id!(status) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)

Since:

  • 1.0.0



272
273
274
# File 'lib/attio/resources/attributes.rb', line 272

private def validate_status_id!(status)
  raise ArgumentError, "Status ID is required" if status.nil? || status.to_s.strip.empty?
end