Modifying Access Codes

Learn how to update your access codes, and ensure that the changes are successfully set on the device.

1. Update the access code using the API

You can update any active or upcoming access codes using the Update Access Code request.

When modifying an access code, adjust the properties of the access code, such as the code, name, starts_at, and ends_at to the new desired values.

Request:

access_code_id = "1bbd1eba-e4a2-4f96-b1b9-8498a5405b2b"

updated_access_code = seam.access_codes.update(
  access_code = access_code_id,
  name = "my updated code name",
  code = "5432",
  starts_at = "2025-02-01T16:00:00Z",
  ends_at = "2025-02-22T12:00:00Z"
)

pprint(updated_access_code)

Response:

AccessCode(access_code_id='1bbd1eba-e4a2-4f96-b1b9-8498a5405b2b',
           device_id='6aae9d08-fed6-4ca5-8328-e36849ab48fe',
           type='time_bound',
           code='5432',
           created_at='2023-10-19T02:21:58.738Z',
           errors=[],
           warnings=[],
           starts_at='2025-02-01T16:00:00.000Z',
           ends_at='2025-02-22T12:00:00.000Z',
           name='my updated code name',
           status='unset',
           common_code_key=None,
           is_managed=True,
           is_waiting_for_code_assignment=None,
           is_scheduled_on_device=False,
           pulled_backup_access_code_id=None,
           is_backup_access_code_available=False,
           is_backup=None,
           appearance=None,
           is_external_modification_allowed=False)

2. Verify that the access code has been updated

For a permanent access code

There are two methods to verify that a permanent access code has been set on the device:

Polling Method

Utilize the access_code_id returned in the response from the create endpoint to invoke the Get Access Code endpoint. A basic implementation would involve polling this endpoint until the status of the access code updates to set.

If the status remains setting for a very long time, or if the access_code object contains any warnings or errors properties, consult our guide on "Troubleshooting Access Code Issues" for further guidance.

Webhook Events Method

Monitor the incoming events on your webhook. Be on the lookout for the access_code.set_on_device event, which indicates the successful setting of the access code on the device.

However, if you receive access_code.failed_to_set_on_device or access_code.delay_in_setting_on_device events, it's crucial to refer to the "Troubleshooting access code issues" guide for assistance.

For a time-bound access code

There are two methods to verify that a time-bound access code has been set on the device:

Polling Method

Use the access_code_id provided in the response from the create endpoint to call the Get Access Code endpoint. In a basic implementation, you would poll this endpoint at the starts_at time to check if the access code's status is updated to set.

If the status remains setting, or if the access_code object displays any warnings or errors, refer to our "Troubleshooting Access Code Issues" guide for assistance.

Webhook Events Method

Monitor the incoming events on your webhook. Be on the lookout for the access_code.set_on_device event, which indicates the successful setting of the access code on the device.

However, if you receive access_code.failed_to_set_on_device or access_code.delay_in_setting_on_device events, it's crucial to refer to the "Troubleshooting access code issues" guide for assistance.


Special Case #1: Changing an ongoing access code to time-bound access

To convert a permanent access code to time-bound access, you must set the starts_at and ends_at properties to the timeframe that you want for the access code.

1. Confirm that the access code starts as an ongoing code.

Request:

access_code_id="daf89de3-ad3a-49aa-93bd-25f27d58f699"
access_code = seam.access_codes.get(access_code_id)

pprint("Access code ID: " + access_code.access_code_id)
pprint("Type: " + access_code.type)
pprint("Starts at: " + str(access_code.starts_at))
pprint("Ends at: " + str(access_code.ends_at))

Response:

'Access code ID: daf89de3-ad3a-49aa-93bd-25f27d58f699'
'Type: ongoing'
'Starts at: None'
'Ends at: None'

2. Update the code to set starts_at and ends_at timestamps.

Request:

access_code_id="daf89de3-ad3a-49aa-93bd-25f27d58f699"
access_code = seam.access_codes.get(access_code_id)

pprint(seam.access_codes.update(
  access_code = access_code_id,
  starts_at = "2025-01-01T16:00:00Z",
  ends_at = "2025-01-22T12:00:00Z"
))

Response:

AccessCode(access_code_id='daf89de3-ad3a-49aa-93bd-25f27d58f699',
           device_id='6aae9d08-fed6-4ca5-8328-e36849ab48fe',
           type='time_bound',
           .
           .
           .
           starts_at='2025-01-01T16:00:00.000Z',
           ends_at='2025-01-22T12:00:00.000Z',
           name='my ongoing code',
           .
           .
           .
           )

3. Confirm that the type has changed to time_bound.

Request:

access_code_id="daf89de3-ad3a-49aa-93bd-25f27d58f699"
access_code = seam.access_codes.get(access_code_id)

pprint("Access code ID: " + access_code.access_code_id)
pprint("Type: " + access_code.type)
pprint("Starts at: " + str(access_code.starts_at))
pprint("Ends at: " + str(access_code.ends_at))

Response:

'Access code ID: daf89de3-ad3a-49aa-93bd-25f27d58f699'
'Type: time_bound'
'Starts at: 2025-01-01T16:00:00.000Z'
'Ends at: 2025-01-22T12:00:00.000Z'

Special Case #2: Changing a time-bound access code to permanent access

When converting a time-bound code to a permanent one, you'll also need to set the type property of the access code to ongoing.

1. Confirm that the access code starts as a time-bound code.

Request:

access_code_id="daf89de3-ad3a-49aa-93bd-25f27d58f699"
access_code = seam.access_codes.get(access_code_id)

pprint("Access code ID: " + access_code.access_code_id)
pprint("Type: " + access_code.type)
pprint("Starts at: " + str(access_code.starts_at))
pprint("Ends at: " + str(access_code.ends_at))

Response:

'Access code ID: daf89de3-ad3a-49aa-93bd-25f27d58f699'
'Type: time_bound'
'Starts at: 2025-01-01T16:00:00.000Z'
'Ends at: 2025-01-22T12:00:00.000Z'

2. Update the code to set the type to ongoing.

Request:

access_code_id="daf89de3-ad3a-49aa-93bd-25f27d58f699"
access_code = seam.access_codes.get(access_code_id)

pprint(seam.access_codes.update(
  access_code = access_code_id,
  type = "ongoing"
))

Response:

AccessCode(access_code_id='daf89de3-ad3a-49aa-93bd-25f27d58f699',
           device_id='6aae9d08-fed6-4ca5-8328-e36849ab48fe',
           type='ongoing',
           .
           .
           .
           starts_at=None,
           ends_at=None,
           name='my ongoing code',
           .
           .
           .
           )

3. Confirm that the type has changed to ongoing and the starts_at and ends_at are None.

Request:

access_code_id="daf89de3-ad3a-49aa-93bd-25f27d58f699"
access_code = seam.access_codes.get(access_code_id)

pprint("Access code ID: " + access_code.access_code_id)
pprint("Type: " + access_code.type)
pprint("Starts at: " + str(access_code.starts_at))
pprint("Ends at: " + str(access_code.ends_at))

Response:

'Access code ID: daf89de3-ad3a-49aa-93bd-25f27d58f699'
'Type: ongoing'
'Starts at: None'
'Ends at: None'