Class: Attio::Resources::Records Private

Inherits:
Base
  • Object
show all
Defined in:
lib/attio/resources/records.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.

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

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

Instance Method Details

#assert(object:, matching_attribute:, 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.

Assert (upsert) a record based on a matching attribute.

This method creates or updates a record based on a matching attribute, providing upsert functionality. If a record with the matching attribute value exists, it will be updated; otherwise, a new record will be created.

Examples:

Assert a person by email

record = client.records.assert(
  object: 'people',
  matching_attribute: 'email',
  data: {
    name: 'Jane Doe',
    email: '[email protected]',
    company: { target_object: 'companies', target_record_id: 'company123' }
  }
)

Parameters:

  • object (String)

    The object type (e.g., 'people', 'companies')

  • matching_attribute (String)

    The attribute to match against for upsert

  • data (Hash)

    The record data to create or update

Returns:

  • (Hash)

    The created or updated record data

Raises:

  • (ArgumentError)

    if object, matching_attribute, or data is invalid

Since:

  • 1.0.0



179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/attio/resources/records.rb', line 179

def assert(object:, matching_attribute:, data:)
  validate_required_string!(object, "Object type")
  validate_required_string!(matching_attribute, "Matching attribute")
  validate_record_data!(data)

  request_body = {
    data: data,
    matching_attribute: matching_attribute,
  }

  request(:put, "objects/#{object}/records", request_body)
end

#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 new record.

Examples:

Create a person

record = client.records.create(
  object: 'people',
  data: {
    name: 'Jane Doe',
    email: '[email protected]',
    company: { target_object: 'companies', target_record_id: 'company123' }
  }
)

Parameters:

  • object (String)

    The object type to create the record in

  • data (Hash)

    The record data to create

Returns:

  • (Hash)

    The created record data

Raises:

  • (ArgumentError)

    if object is nil/empty or data is invalid

Since:

  • 1.0.0



112
113
114
115
116
# File 'lib/attio/resources/records.rb', line 112

def create(object:, data:)
  validate_required_string!(object, "Object type")
  validate_record_data!(data)
  request(:post, "objects/#{object}/records", data)
end

#delete(object:, id:) ⇒ 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.

Delete a record.

Examples:

client.records.delete(object: 'people', id: 'abc123')

Parameters:

  • object (String)

    The object type

  • id (String)

    The record ID to delete

Returns:

  • (Hash)

    Deletion confirmation

Raises:

  • (ArgumentError)

    if object or id is nil or empty

Since:

  • 1.0.0



150
151
152
153
154
# File 'lib/attio/resources/records.rb', line 150

def delete(object:, id:)
  validate_required_string!(object, "Object type")
  validate_id!(id, "Record")
  request(:delete, "objects/#{object}/records/#{id}")
end

#get(object:, id:) ⇒ 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.

Retrieve a specific record by ID.

Examples:

record = client.records.get(object: 'people', id: 'abc123')

Parameters:

  • object (String)

    The object type (e.g., 'people', 'companies')

  • id (String)

    The record ID

Returns:

  • (Hash)

    The record data

Raises:

  • (ArgumentError)

    if object or id is nil or empty

Since:

  • 1.0.0



89
90
91
92
93
# File 'lib/attio/resources/records.rb', line 89

def get(object:, id:)
  validate_required_string!(object, "Object type")
  validate_id!(id, "Record")
  request(:get, "objects/#{object}/records/#{id}")
end

#list(object:, filter: nil, sort: nil, limit: nil, offset: nil, **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.

Query and list records for a specific object type.

This method allows you to retrieve records with optional filtering, sorting, and pagination parameters.

Examples:

Basic listing

records = client.records.list(object: 'people')

With filters

records = client.records.list(
  object: 'people',
  filters: { name: { contains: 'John' } },
  limit: 50
)

Parameters:

  • object (String)

    The object type to query (e.g., 'people', 'companies')

  • params (Hash)

    Query parameters including filters, sorts, and pagination

Options Hash (**params):

  • :filters (Hash)

    Filtering criteria

  • :sorts (Array)

    Sorting options

  • :limit (Integer)

    Number of records to return

  • :cursor (String)

    Pagination cursor for next page

Returns:

  • (Hash)

    API response containing records and pagination info

Raises:

  • (ArgumentError)

    if object is nil or empty

Since:

  • 1.0.0



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/attio/resources/records.rb', line 47

def list(object:, filter: nil, sort: nil, limit: nil, offset: nil, **params)
  validate_required_string!(object, "Object type")

  # Build query parameters with filtering and sorting support
  query_params = build_query_params({
    filter: filter,
    sort: sort,
    limit: limit,
    offset: offset,
    **params,
  })

  request(:post, "objects/#{object}/records/query", query_params)
end

#list_all(object:, filter: nil, sort: nil, page_size: 50) ⇒ Enumerator

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 all records with automatic pagination

Parameters:

  • object (String)

    The object type to query

  • filter (Hash) (defaults to: nil)

    Filtering criteria

  • sort (String) (defaults to: nil)

    Sorting option

  • page_size (Integer) (defaults to: 50)

    Number of records per page

Returns:

  • (Enumerator)

    Enumerator that yields each record

Since:

  • 1.0.0



68
69
70
71
72
73
74
75
76
77
# File 'lib/attio/resources/records.rb', line 68

def list_all(object:, filter: nil, sort: nil, page_size: 50)
  validate_required_string!(object, "Object type")

  query_params = build_query_params({
    filter: filter,
    sort: sort,
  })

  paginate("objects/#{object}/records/query", query_params, page_size: page_size)
end

#update(object:, id:, 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 record.

Examples:

Update a person's name

record = client.records.update(
  object: 'people',
  id: 'abc123',
  data: { name: 'Jane Smith' }
)

Parameters:

  • object (String)

    The object type

  • id (String)

    The record ID to update

  • data (Hash)

    The updated record data

Returns:

  • (Hash)

    The updated record data

Raises:

  • (ArgumentError)

    if object, id, or data is invalid

Since:

  • 1.0.0



133
134
135
136
137
138
# File 'lib/attio/resources/records.rb', line 133

def update(object:, id:, data:)
  validate_required_string!(object, "Object type")
  validate_id!(id, "Record")
  validate_record_data!(data)
  request(:patch, "objects/#{object}/records/#{id}", data)
end

#update_with_put(object:, id:, 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 record using PUT (replace operation).

This method performs a complete replacement of the record, unlike the regular update method which uses PATCH. For multiselect fields, this overwrites the values instead of appending to them.

Examples:

Replace a person's data

record = client.records.update_with_put(
  object: 'people',
  id: 'abc123',
  data: {
    name: 'Jane Smith',
    email: '[email protected]',
    tags: ['customer', 'vip']  # This will replace all existing tags
  }
)

Parameters:

  • object (String)

    The object type (e.g., 'people', 'companies')

  • id (String)

    The record ID to replace

  • data (Hash)

    The complete record data to replace with

Returns:

  • (Hash)

    The updated record data

Raises:

  • (ArgumentError)

    if object, id, or data is invalid

Since:

  • 1.0.0



215
216
217
218
219
220
221
222
# File 'lib/attio/resources/records.rb', line 215

def update_with_put(object:, id:, data:)
  validate_required_string!(object, "Object type")
  validate_id!(id, "Record")
  validate_record_data!(data)

  request_body = { data: data }
  request(:put, "objects/#{object}/records/#{id}", request_body)
end

#validate_record_data!(data) ⇒ 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.

Validates that the data parameter is present and is a hash.

Parameters:

  • data (Hash, nil)

    The data to validate

Raises:

  • (ArgumentError)

    if data is nil or not a hash

  • (ArgumentError)

Since:

  • 1.0.0



229
230
231
232
# File 'lib/attio/resources/records.rb', line 229

private def validate_record_data!(data)
  raise ArgumentError, "Data is required" if data.nil?
  raise ArgumentError, "Data must be a hash" unless data.is_a?(Hash)
end